Hello all,
May I ask a question about OLS regression (Y=alpha+a1*X1+a2*X2+a3*X3)?
In Table1, I have Y, X1, X2 and X3 for each Firm_ID on each Date,
Table 1 | ||||||
Firm_ID | Year | Date | Y | X1 | X2 | X3 |
1 | 1994 | 02/17/1994 | 371 | -445 | 2138 | -196 |
1 | 1994 | 02/18/1994 | 3248 | -454 | 3457 | 2389 |
1 | 1994 | 02/22/1994 | 1678 | 5992 | -62 | 1747 |
1 | 1995 | 02/17/1995 | -11 | -12 | 1848 | -263 |
1 | 1995 | 02/18/1995 | -3803 | -1253 | 3372 | 1806 |
1 | 1995 | 02/22/1995 | 4456 | 3632 | -21 | 291 |
2 | 1994 | 02/17/1994 | -8995 | 3925 | 8434 | -326 |
2 | 1994 | 02/18/1994 | 229 | -506 | -235 | 2486 |
2 | 1994 | 02/22/1994 | 208 | -184 | -594 | -204 |
2 | 1995 | 02/17/1995 | -12 | -223 | 4152 | -32 |
2 | 1995 | 02/18/1995 | 1578 | 4563 | 369 | -88 |
I expect to get alpha, a1, a2 and a3 for each Firm_ID in each year (e.g., Table2).
Table 2 | |||||
Firm_ID | Year | alpha | a1 | a2 | a3 |
1 | 1994 | alpha 1 | Aaa1 | Aaa2 | Aaa3 |
1 | 1995 | alpha 2 | Bbb1 | Bbb2 | Bbb3 |
2 | 1994 | alpha 3 | Ccc1 | Ccc2 | Ccc3 |
2 | 1995 | alpha 4 | Ddd1 | Ddd2 | Ddd3 |
Could you please give me some advice?
Many thanks in advance.
data table1; infile cards dsd dlm=","; input firm_id :$5. Year :8. Date :MMDDYY10. Y :8. X1 :8. X2 :8. X3 :8. ; cards; 1,1994,02/17/1994,371,-445,2138,-196 1,1994,02/18/1994,3248,-454,3457,2389 1,1994,02/22/1994,1678,5992,-62,1747 1,1995,02/17/1995,-11,-12,1848,-263 1,1995,02/18/1995,-3803,-1253,3372,1806 1,1995,02/22/1995,4456,3632,-21,291 2,1994,02/17/1994,-8995,3925,8434,-326 2,1994,02/18/1994,229,-506,-235,2486 2,1994,02/22/1994,208,-184,-594,-204 2,1995,02/17/1995,-12,-223,4152,-32 2,1995,02/18/1995,1578,4563,369,-88 ;;; run;
In this simple example, you cannot estimate the coefficients of three independent variables since you only have 3 data points for each year/firm combination. To fit a model with 3 independent variables, you would need 4 or more data points for each year/firm combination.
Assuming your have more data, you can estimate the regression coefficients using PROC REG
proc reg data=table1 outest=coefficients;
by firm_id year;
model y=x1 x2 x3;
run;
If you have lots of firms and years, this could take a very long time, and then you would probably wise to turn off the ODS GRAPHICS and turn off output to HTML before you run this, which will speed this up, and then view the coefficients in the output data set. So you would place these commands before PROC REG.
ods graphics off;
ods html select none;
From now on, no need to show us a screen capture or table of the data, all we need is the SAS data step code which you also provided.
In this simple example, you cannot estimate the coefficients of three independent variables since you only have 3 data points for each year/firm combination. To fit a model with 3 independent variables, you would need 4 or more data points for each year/firm combination.
Assuming your have more data, you can estimate the regression coefficients using PROC REG
proc reg data=table1 outest=coefficients;
by firm_id year;
model y=x1 x2 x3;
run;
If you have lots of firms and years, this could take a very long time, and then you would probably wise to turn off the ODS GRAPHICS and turn off output to HTML before you run this, which will speed this up, and then view the coefficients in the output data set. So you would place these commands before PROC REG.
ods graphics off;
ods html select none;
From now on, no need to show us a screen capture or table of the data, all we need is the SAS data step code which you also provided.
Hello @Alexxxxxxx ,
Are you sure you don't need a PANEL DATA REGRESSION?
Your firms are cross-sections and your years make time series for output and inputs.
Time Series Cross-Sectional regression (=panel data regression) can be done with the old procedure PROC TSCSREG (SAS/ETS).
Newer and better procedures are PROC PANEL and PROC CPANEL (SAS VIYA Econometrics using CAS engine).
This way, you get one big model instead of several independent models.
BR,
Koen
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.