BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amanjot_42
Fluorite | Level 6

Hi guys,

 

I am trying to run a regression on daily returns for every fiscal year. But the minimum number of observations for each fiscal year required for a firm are 200. If there are not enough observations (less than 200), I would like to drop that fiscal year from my regression analysis. Can you please help me in this regard. The sample ranges from the fiscal year - 2013 to 2019 daily observations for different firms. My regression model is to regress stock returns against the market returns for every fiscal year (minimum number of daily returns required to be 200) and for every firm.

 

Firm_ID     date               stock_returns         market_returns              fiscal_year

11           02/04/2013                 7                           1.5                           2014

11            03/04/2013                9                           -10                            2014

.............

12           02/04/2013                 5                           3.5                           2014

12            03/04/2013                4                           -1                             2014

............

13           02/04/2013                 6                           0.9                           2014

13            03/04/2013                4                           -1                             2014

............

 

Regards,

Amanjot

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Sort by firm and year, and then run a double do loop:

proc sort data=have;
by firm_id fiscal_year;
run;

data want;
count = 0;
do until (last.fiscal_year);
  set have;
  by firm_id fiscal_year;
  count + 1;
end;
do until (last.fiscal_year);
  set have;
  by firm_id fiscal_year;
  if count ge 200 then output;
end;
drop count;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Sort by firm and year, and then run a double do loop:

proc sort data=have;
by firm_id fiscal_year;
run;

data want;
count = 0;
do until (last.fiscal_year);
  set have;
  by firm_id fiscal_year;
  count + 1;
end;
do until (last.fiscal_year);
  set have;
  by firm_id fiscal_year;
  if count ge 200 then output;
end;
drop count;
run;
amanjot_42
Fluorite | Level 6

Thank you so much!

 

It worked perfectly

 

Regards

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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