- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear,
Im relatively new to SAS and I'm experiencing some problems with a two-way clustering I have to do for my panel data. Since this option is available by default, I'm using someone's macro that I found on this website: https://sites.google.com/site/markshuaima/home/two-way-clustered-standard-errors-and-sas-code. I saw this website being referred to in a previous post. This is my log:
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The error is
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Did who ever wrot that macro provide any descriptions of what the input data set should look like? Does your data match those requirements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The error is
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear sir,
I also thought that was part of the problem.
Using the /noint command and deleting the intercept term from the code did solve practically all of the errors, So I think I got the standard errors I need in column G which is at the end of my output, I thank you for your comment. However, looking at the macro code, I think the output should also give me the t-statistics and perform t/std error. That however does not show in my output, nor does my log show any errors. Do you have any clue on why that might be the reason?
I'm referring to the last 9-10 lines of the code. I should admit that I THINK colums G is provided the adjusted standard errors (adjusted after two-dimensional clustering) but I'm not entirely sure. (For now I'm using these numbers to compute the t-statistic myself, however, normally the code should provide them). Column G has 48 numbers (one for each of my variables)
Here is the full code:
/* Generated Code (IMPORT) */
/* Source File: spss data panelregr.sav */
/* Source Path: /home/poulsinghps0/finale SAS */
/* Code generated on: 30-05-17 17:31 */
%web_drop_table(WORK.sasfeedback);
FILENAME REFFILE '/home/poulsinghps0/finale SAS/spss data panelregr.sav';
PROC IMPORT DATAFILE=REFFILE
DBMS=SAV
OUT=WORK.sasfeedback;
RUN;
PROC CONTENTS DATA=WORK.sasfeedback; RUN;
%web_open_table(WORK.sasfeedback);
/*July ,2015*/
/*This sas macro code is modified by Mark (Shuai) Ma based on the two-way clustered SE code from Professor John McInnis *******/
/*According to Petersen (2008) and Thompson (2011), there are three steps to estimate two-way clustered SEs: */
/*1. estimate firm-clustered VARIANCE-COVARIANCE matrix V firm,*/
/*2. estimate time-clustered VARIANCE-COVARIANCE matrix V time,*/
/*3. estimate heteroskedasticity robust white VARIANCE-COVARIANCE matrix (V white) when there is only one observations each firm-time intersection,*/
/*or, estimate firm-time intersection clustered VARIANCE-COVARIANCE matrix (V firm-time) when there is more than one observations each firm-time intersection,*/
/*This code allows the user to closely follows the formula given by Petersen (2008) and Thompson (2011).*/
/********************************************************************************************************************************/
/*If you use this code, please add a footnote:*/
/*To obtain unbiased estimates in finite samples,the clustered standard error is adjusted by (N-1)/(N-P)× G/(G-1),where N is the sample size, P is the number of independent variables, and G is the number of clusters. */
/*For details, please see my note on two-way clustered standard errors avaiable on SSRN and my website https://sites.google.com/site/markshuaima/home.*/
/*Lastly, I post this code for the communication purpose without any warranty or guaranty of accuracy or support.*/
/*I tried my best to ensure the accuracy of the codes, but I could not exclude the possibility that there might still be errors. If any error is found, please get me know immediately.*/
/********************************************************************************************************************************/
/*Input explanations */
/* After running the macro code below, you will need to run the following command,
you only need to change the names of datasets and variables and "multi" value in the following command, and results will be in dataset "A.results"*/
/*****************command*******************************************************************************************************/
/*%REG2DSE(y=DV, x=INDV, firm=firmid, time=timeid, multi=0, dataset=A.data, output=A.results);*/
/**************Variable Explanation*********************************************************************************************/
/* 1. A.data: A is your library name, data is your input dataset name,*/
/*A.results : A is your library name, results is the name you want for your output dataset ,*/
/*2. DV: the dependent variable, */
/*INDV: the list of your independent variable(s),*/
/*3. firmid: the firm identifier (such as gvkey, permno) ,*/
/*timeid: the time identifier (such as fyear, date),*/
/*4. multi=0 or 1 (you need to choose whether you use 0 or 1 ) */
/* if you have one observation per firm-time (intersection of two dimendions), you need to have multi=0*/
/* if you have multiple observations per firm-time (intersection of two dimendions) , you need to have multi=1*/
/********************************************************************************************************************************/
/************************The macro code is as follows*************************************/
%MACRO REG2DSE(y, x, firm, time, multi, dataset, output);
proc surveyreg data=WORK.sasfeedback;
cluster id;
model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 /covb noint ;
ods output covb=firm;
ods output FitStatistics=fit;
run;quit;
proc surveyreg data=WORK.sasfeedback;
cluster t;
model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 /covb noint ;
ods output covb=time;
run;quit;
%if 0=1 %then %do;
proc surveyreg data=WORK.sasfeedback;
cluster t id;
model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 / covb noint;
ods output covb=both ;
ods output parameterestimates=parm;
run;quit;
data parm; set parm;keep parameter estimate;run;
%end;
%else %if 0=0 %then %do;
proc reg data=WORK.sasfeedback;
model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 /hcc acov covb noint;
ods output acovest=both ;
ods output parameterestimates=parm;
run;quit;
data both; set both; parameter=Variable; run;
data both; set both;drop variable Dependent Model;run;
data parm; set parm;parameter=Variable;Estimates=Estimate;keep parameter estimates;run;
%end;
data parm1; set parm;
n=_n_;m=1;keep m n;run;
data parm1;set parm1;
by m;if last.m;keep n;run;
data both; set both;
keep indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47;
run;
data firm; set firm;
keep indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47;
run;
data time; set time;
keep indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47;
run;
data fit1; set fit;
parameter=Label1;
Estimates=nValue1;
if parameter="R-square" then output;
run;
data fit1; set fit1;
n=1;
keep parameter Estimates n;
run;
proc iml;use both;read all var _num_ into Z;print Z;use firm;read all var _num_ into X;print X;
use time;read all var _num_ into Y;print Y;use parm1;
read all var _num_ into n;print n;B=X+Y-Z;C=I(n);D=J(n,1);E=C#B;
F=E*D;G=F##.5;
print B;print G;
create b from G [colname='stderr']; append from G;quit;
data results; merge parm B ;
tstat=estimates/stderr;n=0;run;
data resultsfit; merge results fit1;by n;
run;
data work.results; set resultsfit;
drop n;
run;
%MEND REG2DSE;
%REG2DSE(y=DV, x=INDV, firm=firmid, time=timeid, multi=0, dataset=work.data, output=work.results)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
After you run the macro, submit
proc print data=results;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That worked, thank you very much.