BookmarkSubscribeRSS Feed
shenflow
Obsidian | Level 7

I have an unbalanced panel dataset of the following form (simplified):

 

data have;
	input ID YEAR EARN LAG_EARN;
	datalines;
1       1960      450      
1       1961      310      450
1       1962      529      310
2       1978      10
2       1979      15       10
2       1980      8        15
2       1981      10       8
2       1982      15       10
2       1983      8        15
2       1984      10       8
3       1972      1000 
3       1973      1599     1000
3       1974      1599     1599
;
run;​ 

 

I now want to estimate the following model for each ID:

proc reg;
     by ID;
     EARN = LAG_EARN;
run;

However, I want to do this for rolling windows of some size. Say for example for windows of size 2. The window should only contain non-empty observations. For example, in the case of firm A, the window is applicable from 1961 onwards and thus only one time (since only one year follows after 1961 and the window is supposed to be of size 2).

 

So that finally, I get a table with year columns and firm rows. The table should indicate the following: The regression model (with window size 2) has been performed one time for firm A. The quantity of available years, has only allowed one estimation of this model. Put differently, in 1962 the coefficient of the regression model has a value of X based on the 2 year prior window. Applying the same logic to the other two firms, one can get the following table. "X" representing the respective estimated coefficient value in certain year for firm A/B/C based on the 2-year window and "n" indicating the non-existence of such a value:

 

data want;
	input ID 1962 1974 1980 1981 1982 1983 1984;
	datalines;
1 X n n n n n n
2 n n X X X X X      
3 n X n n n n n 
;
run;​ 

 

I do not know how to execute this. Furthermore, I would like to create a macro that allows me to estimate different rolling window models while still creating analogous output dataframes. I would appreciate any help with it, since I have been struggling quite some time now.

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If you do an internet search for "Rolling Window Regression in SAS", you find a number of solutions, one involving no macros (that's the one I recommend) and several involving macros. So there's no need for you to write macro (or non-macro) code yourself.

 

You would have to modify those codes to account for the unbalanced nature of your data.

--
Paige Miller
shenflow
Obsidian | Level 7

Thanks for the reply. Yea I came across those. But I do not know how to adjust those methods accordingly. That is my issue.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 456 views
  • 0 likes
  • 2 in conversation