Hello, I am new to EVIEWS programming and am trying to make some looping regression. The background is that I have made a 1000 simulation of series "nx" (like nx1, nx2, ...) and stored it on "nx" page of my work file. Then, I want to solve the model consisting of 5 variables (a g nx ra rl) VAR(since I am taking nx from another source, I put nx as an exogenous variable) on page "main". This means I will have 1000 different outcomes for (a g ra rl) for each nx series respectively. I am asking for ChatGPT to provide code but it is not working and "!NUM_OBS_A is not defined or is an illegal command in "!NUM_OBS_A = @OBS(RESULT\A)" in 1.PRG on line 39." error message keeps popping. Below is what I have done so far.
' Open the workfile
wfopen "C:\Users\myagm\OneDrive\Desktop\EVIEWS\nxvarnom.wf1"
!num_simulations = 1000
pageselect nx
for !i = 1 to !num_simulations
' Define the simulated series name dynamically
%nx_series = "nx" + @str(!i) ' e.g., nx1, nx2
' Switch to the NX page
pageselect nx
' Check if the series exists in the NX page
if @isobject(%nx_series) then
' Create a static version of the series in the NX page
series temp_static = {%nx_series}
' Switch to the MAIN page
pageselect main
' Copy the static series to the MAIN page with a unique name
copy(merge) nx\temp_static main\nx
pageselect main
' Define the sample range
smpl 2024Q4 2029Q4
' Solve the model
model1.solve(stochastic)
' Switch to the RESULT page to store results
pageselect result
' Manually calculate the maximum number of observations across the series
!num_obs_a = @obs(result\a)
!num_obs_g = @obs(result\g)
!num_obs_nx = @obs(result\nx)
!num_obs_ra = @obs(result\ra)
!num_obs_rl = @obs(result\rl)
' Find the maximum of all the observation counts
!max_obs = @max(!num_obs_a, !num_obs_g, !num_obs_nx, !num_obs_ra, !num_obs_rl)
' Initialize count of non-NA values
!count = 0
' Loop through the series result\a and count non-NA values
for !obs = 1 to !max_obs
if result\a(!obs) != @nan then
!count = !count + 1
endif
next
' If the series is filled with NA, start appending from observation 1
if !count = 0 then
!start_obs = 1
else
' Otherwise, find the last non-missing observation and append after that
!start_obs = !count + 1
endif
' Loop through each repetition (e.g., repid in panel)
for !repid = 1 to 1000
' Append the results to the result page for the current repid and obsid
result\a(!start_obs + !repid - 1) = main\a_0
result\g(!start_obs + !repid - 1) = main\g_0
result\nx(!start_obs + !repid - 1) = main\nx
result\ra(!start_obs + !repid - 1) = main\ra_0
result\rl(!start_obs + !repid - 1) = main\rl_0
next
else
' Log a message if the series does not exist
show "Series not found in NX page"
endif
next
Looped regression
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Who is online
Users browsing this forum: No registered users and 2 guests
