R square by firm and time
Posted: 12 August 2015 04:53 PM   [ Ignore ]
Newbie
Rank
Total Posts:  6
Joined  2015-08-12

Hello~
I would like to run a regression by firm and year.
(Actually, I am trying to get price nonsynchronicity with market,industry and firm return)
How do I get R square for each firm by year?
For example, the number of firm is 10,000 and year ranges from 1980 to 2010.
Could you plz help me?

Many thanks in advance.

Profile
 
 
Posted: 12 August 2015 07:04 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

Hi,

To do a regression for every firm, you can add ‘by permno’ (or whatever firm identifier you have) in a proc reg. Make sure the dataset is sorted by permno.

proc reg data d_em4_wins 
noprint tableout edf outest 
e_regout;
by indYear/* have here 'by permno' or 'by SIC', etc */
model ca oancf_ia dind oancf_ia_dind  sale_ch ppegt ;
output out=e_em r=em/* this creates another output dataset, in this case, adding the residual renaming it as em*/
quit

Whatever you specify as ‘outest = ...’ will have an _RSQ_ variable, which is the R-squared for that group.

Best,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 16 August 2015 02:03 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  6
Joined  2015-08-12

Hi Joost,

I followed your suggestion, but I got zero residual. As a result. R-square is zero for all observations.
However, I got positive R-square when I check part of my sample with Stata.

My sample is daily data, but I want to run regression by group and year.
Difference from your code is “by group year” instead of “by indYear.”
Would you correct my error?

Thank you so much.

Profile
 
 
Posted: 16 August 2015 03:34 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

Hi,

add “by VARNAME;”, where varname is a variable that holds something that is the same for all obs in the group. For example, that can be: “by gvkey” if you repeat regressions by firm, or “by fyear” if you repeat it by year, or “by SIC” for industries, or “by SIC fyear” to repeat by industry year. Do not add ‘group’, if there is no variable group (not “by group year”).

Also, keep an eye on the log in SAS. Error descriptions can help you understand what is going on.

Hope this helps,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile