Programming the statistical procedures from SAS

How to run a fixed effects linear regression with 2-way clustered standard errors?

Reply
Regular Learner
Posts: 1

How to run a fixed effects linear regression with 2-way clustered standard errors?

[ Edited ]

I have financial panel data on approx. 3000 firms for 30 years on which I need to run linear regressions with fixed effects for INDUSTRY and YEAR with standard errors clustered on INDUSTRY and YEAR. So far, I have run the fixed effects model using PROC GLM/Class industry year - which readily generates the fixed effects but does not cluster. I have also used a macro (reproduced below) which generates 2-way clustered standard errors - but this does not accommodate the large number of fixed effects (100 industry plus 30 year dummies), which I generate manually. How may I do the fixed effects and clustered standard errors together in SAS 9.4? The dependent variable and independent variables (apart from the industry and year dummies) are continuous variables.

 

******************************************************************************************************************************************

%MACRO clus2OLS(yvar, xvars, cluster1, cluster2, dset);

/* do interesection cluster*/

proc surveyreg data=&dset; cluster &cluster1 &cluster2; model &yvar= &xvars / covb; ods output CovB = CovI; quit;

/* Do first cluster */

proc surveyreg data=&dset; cluster &cluster1; model &yvar= &xvars / covb; ods output CovB = Cov1; quit;

/* Do second cluster */

proc surveyreg data=&dset; cluster &cluster2; model &yvar= &xvars / covb; ods output CovB = Cov2 ParameterEstimates = params; quit;

/* Now get the covariances numbers created above. Calc coefs, SEs, t-stats, p-vals using COV = COV1 + COV2 - COVI*/

proc iml; reset noprint; use params;

read all var{Parameter} into varnames;

read all var _all_ into b;

use Cov1; read all var _num_ into x1;

use Cov2; read all var _num_ into x2;

use CovI; read all var _num_ into x3;

cov = x1 + x2 - x3; /* Calculate covariance matrix */

dfe = b[1,3]; stdb = sqrt(vecdiag(cov)); beta = b[,1]; t = beta/stdb; prob = 1-probf(t#t,1,dfe); /* Calc stats */

print,"Parameter estimates",,varnames beta[format=8.4] stdb[format=8.4] t[format=8.4] prob[format=8.4];

conc = beta || stdb || t || prob;

cname = {"estimates" "stderror" "tstat" "pvalue"};

create clus2dstats from conc [ colname=cname ];

append from conc;

conc = varnames;

cname = {"varnames"};

create names from conc [ colname=cname ];

append from conc;

quit;

data clus2dstats; merge names clus2dstats; run;

%MEND clus2OLS;

Ask a Question
Discussion stats
  • 0 replies
  • 134 views
  • 0 likes
  • 1 in conversation