Monthly regression

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Monthly regression

Postby Sima77 » Fri Sep 09, 2022 1:10 pm

I have 3 time series of daily observations for 10 years, and I want to run the regression of every month separately (not rolling regression, I want to use the daily observations of each month to run the regression of that month, and then move to the next month and doing the same and so on. Any suggestions on how to do that?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13323
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monthly regression

Postby EViews Gareth » Fri Sep 09, 2022 2:01 pm

You can create a series of month numbers (starting at 1 for the first month in your sample, then increasing each month) with the following:

Code: Select all

series monthnum = @recode(@trend=0,1,@recode(@month<>@month(-1),monthnum(-1)+1,monthnum(-1)))

(this simply sets the first observation [@trend=0] to 1, then has a test - if the month of the current observation is different from the previous observation, add 1, otherwise stay the same).

Once you have that series you can just have a for loop that loops through the values in that series, setting the sample and estimating the equation.
Follow us on Twitter @IHSEViews

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Monthly regression

Postby Sima77 » Fri Sep 09, 2022 3:52 pm

Amazing! I know how to create the for loop but I did not manage to set the sample using the monthnum series, please can you suggest how to do it?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13323
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monthly regression

Postby EViews Gareth » Fri Sep 09, 2022 8:17 pm

Code: Select all

smpl if monthnum=!i
Follow us on Twitter @IHSEViews

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Monthly regression

Postby Sima77 » Sat Sep 10, 2022 3:02 am

Brilliant. Solved. Million thanks.

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Monthly regression

Postby Sima77 » Sun Sep 11, 2022 2:25 am

Hello again, I have another question. Is there a way to save the residual series of all the sample regressions? now the regression is based on the sample (each month) and not the whole time series. So, when I used "makeresids" commands it saved the residuals of the first month/sample only and it shows N/A for the rest samples/months. I need the residual series of all the samples/months. Please I highly appreciate your suggestions on how to do that.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13323
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monthly regression

Postby EViews Gareth » Sun Sep 11, 2022 12:11 pm

After each regression, copy the residuals into a series. Since the sample is set to the current monthly, the copy will only copy values for the month being estimated.
Follow us on Twitter @IHSEViews

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Monthly regression

Postby Sima77 » Sun Sep 11, 2022 4:56 pm

Thank you so much for your reply. Actually, I have tried that and did not work properly because the length of the time series (10 years) is not identical to the length of the sample (one month). I put the save command of the residual series inside the loop to save the residual series for every month but did not work. It only saved the residuals of the first month of the first series and left the other residual series content as N/A.


Return to “Programming”

Who is online

Users browsing this forum: Google [Bot] and 16 guests