BookmarkSubscribeRSS Feed
windy
Quartz | Level 8

Hi all, 

 

I am doing rolling regressions with quarterly window for each ID group. I have been looking for many solutions and found out that I need to create a quarterly loop and then use proc reg with a by statement to solve my problem. 

My dataset ranges from 1999:1 to 2017:3. The date variable showing the quarters is formatted in YYQC6. There are 75 quarters in total. I want to run 30-quarter rolling window regressions. Please help me to set up the macro for the quarterly loop.

 

Thank you in advance for any help. 

 

Best regards, 

Windy. 

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @windy 

 

Could you please provide some sample data?

 

Thank a lot Smiley Happy

windy
Quartz | Level 8

I provided the data sample below as suggested. 

PaigeMiller
Diamond | Level 26

If you do an internet search for rolling regressions in SAS, there are a number of papers that provide actual code to do this.

 

Also, screen captures of data are never helpful. The proper way to provide data for use in the SAS communities is given here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

--
Paige Miller
windy
Quartz | Level 8

Thank you @PaigeMiller I edited it. I am also looking for the solutions in the internet. But I am too new to SAS, so I am still struggling with understanding the codes. 

 

@ed_sas_member 

This is how the data sample looks like. I made the ID and date in bold. 

 

data WORK.INCORDATA;
infile datalines dsd truncover;

input cd_msa:BEST. cd_msa_gdp:BEST. cd_msa_hpi:BEST. cd_msa_uer:BEST. year:32. quarter:32. _TYPE_:32. _FREQ_:32. delq_reo:32. delq_90d:32. delq_60d:32. delq_ss:32. delq_repch:32. fico:32. cltv:32. dti:32. datenew:YYQC. gdp:32. gdp_growth:32. hpi:32. uer:32
. realgdp:32. realgdp_growth:32. FEDFUNDS:32. MORTGAGE30US:32. State:$12. jury:BEST12. SRR:BEST12. PD:BEST12.;
format cd_msa BEST. cd_msa_gdp BEST. cd_msa_hpi BEST. cd_msa_uer BEST. datenew YYQC. jury BEST12. SRR BEST12. PD BEST12.;
label cd_msa="cd_msa" cd_msa_gdp="cd_msa_gdp" cd_msa_hpi="cd_msa_hpi" cd_msa_uer="cd_msa_uer" State="State" jury="JP" SRR="SRR" PD="PD";
datalines;
. . 29460 . . . . . . . . . . . . . . . . . . . . . . . . .
. . 37460 . . . . . . . . . . . . . . . . . . . . . . . . .
. . 42100 . . . . . . . . . . . . . . . . . . . . . . . . .
10380 . . . 1999 1 7 1 0 0 0 0 0 753 80 31 1999:1 . . . . . . 4.7324444444 6.8779885492 . . .
13644 . . . 1999 1 7 998 0 0 0 0 0 766.92685371 73.71242485 34.651302605 1999:1 . . . . . . 4.7324444444 6.8779885492 . . .
;;;;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 799 views
  • 0 likes
  • 3 in conversation