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

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:

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
62
63 /* Generated Code (IMPORT) */
64 /* Source File: spss data panelregr.sav */
65 /* Source Path: /home/poulsinghps0/finale SAS */
66 /* Code generated on: 29/05/2017 23:00 */
67
68 %web_drop_table(WORK.paneltwowaycluster2);
MLOGIC(WEB_DROP_TABLE): Beginning execution.
MLOGIC(WEB_DROP_TABLE): %LET (variable name is NUM)
MLOGIC(WEB_DROP_TABLE): %LET (variable name is STEPNEEDED)
MLOGIC(WEB_DROP_TABLE): %LET (variable name is STEPSTARTED)
MLOGIC(WEB_DROP_TABLE): %LET (variable name is DSNAME)
MLOGIC(WEB_DROP_TABLE): %DO %WHILE(&dsname ne) loop beginning; condition is TRUE.
MLOGIC(WEB_DROP_TABLE): %IF condition %sysfunc(exist(&dsname)) is TRUE
MLOGIC(WEB_DROP_TABLE): %LET (variable name is STEPNEEDED)
MLOGIC(WEB_DROP_TABLE): %IF condition (&stepstarted eq 0) is TRUE
MLOGIC(WEB_DROP_TABLE): %LET (variable name is STEPSTARTED)
NOTE: Table WORK.PANELTWOWAYCLUSTER2 has been dropped.
MLOGIC(WEB_DROP_TABLE): %IF condition %sysfunc(exist(&dsname,view)) is FALSE
MLOGIC(WEB_DROP_TABLE): %LET (variable name is NUM)
MLOGIC(WEB_DROP_TABLE): %LET (variable name is DSNAME)
MLOGIC(WEB_DROP_TABLE): %DO %WHILE() condition is FALSE; loop will not iterate again.
MLOGIC(WEB_DROP_TABLE): %IF condition &stepstarted is TRUE
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 41.93k
OS Memory 31392.00k
Timestamp 29/05/2017 09:29:28 PM
Step Count 197 Switch Count 30
Page Faults 0
Page Reclaims 15
Page Swaps 0
Voluntary Context Switches 66
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
 
MLOGIC(WEB_DROP_TABLE): Ending execution.
69
70
71 FILENAME REFFILE '/home/poulsinghps0/finale SAS/spss data panelregr.sav';
72
73 PROC IMPORT DATAFILE=REFFILE
74 DBMS=SAV
75 OUT=WORK.paneltwowaycluster2;
76 RUN;
 
NOTE: The import data set has 5170 observations and 59 variables.
NOTE: WORK.PANELTWOWAYCLUSTER2 data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 1967.93k
OS Memory 32932.00k
Timestamp 29/05/2017 09:29:28 PM
Step Count 198 Switch Count 40
Page Faults 0
Page Reclaims 278
Page Swaps 0
Voluntary Context Switches 92
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 4872
 
 
77
78 %MACRO REG2DSE(y, x, firm, time, multi, dataset, output);
79
80 proc surveyreg data=work.paneltwowaycluster2;
81 cluster id;
82 model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16
82 ! etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36
82 ! etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 /covb ;
83 ods output covb=firm;
84 ods output FitStatistics=fit;
85 run;quit;
86
87
88 proc surveyreg data=work.paneltwowaycluster2;
89 cluster t;
90 model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16
90 ! etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36
90 ! etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 /covb ;
91 ods output covb=time;
92 run;quit;
93
94 %if 0=1 %then %do;
95
96 proc surveyreg data=work.paneltwowaycluster2;
97 cluster t id;
98 model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16
98 ! etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36
98 ! etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 / covb;
99 ods output covb=both ;
100 ods output parameterestimates=parm;
101 run;quit;
102
103 data parm; set parm;keep parameter estimate;run;
104
105 %end;
106
107
108 %else %if 0=0 %then %do;
109
110 proc reg data=work.paneltwowaycluster2;
111 model tevpa = indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16
111 ! etf17 etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36
111 ! etf37 etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47 /hcc acov covb;
112 ods output acovest=both ;
113 ods output parameterestimates=parm;
114 run;quit;
115
116 data both; set both; parameter=Variable; run;
117
118 data both; set both;drop variable Dependent Model;run;
119
120 data parm; set parm;parameter=Variable;Estimates=Estimate;keep parameter estimates;run;
121
122 %end;
123
124 data parm1; set parm;
125 n=_n_;m=1;keep m n;run;
126
127 data parm1;set parm1;
128 by m;if last.m;keep n;run;
129
130 data both; set both;
131 keep indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17
131 ! etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37
131 ! etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47;
132 run;
133 data firm; set firm;
134 keep indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17
134 ! etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37
134 ! etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47;
135 run;
136 data time; set time;
137 keep indevolatiliteitpa ETF1 ETF2 ETF3 etf4 etf5 etf6 etf7 etf8 etf9 etf10 etf11 etf12 etf13 etf14 etf15 etf16 etf17
137 ! etf18 etf19 etf20 etf21 etf22 etf23 etf24 etf25 etf26 etf27 etf28 etf29 etf30 etf31 etf32 etf33 etf34 etf35 etf36 etf37
137 ! etf38 etf39 etf40 etf41 etf42 etf43 etf44 etf45 etf46 etf47;
138 run;
139
140 data fit1; set fit;
141 parameter=Label1;
142 Estimates=nValue1;
143 if parameter="R-square" then output;
144 run;
145
146 data fit1; set fit1;
147 n=1;
148 keep parameter Estimates n;
149 run;
150 proc iml;use both;read all var _num_ into Z;print Z;use firm;read all var _num_ into X;print X;
151 use time;read all var _num_ into Y;print Y;use parm1;
152 read all var _num_ into n;print n;B=X+Y-Z;C=I(n);D=J(n,1);E=C#B;
153 F=E*D;G=F##.5;
154 print B;print G;
155 create b from G [colname='stderr']; append from G;quit;
156
157 data results; merge parm B ;
158 tstat=estimates/stderr;n=0;run;
159
160 data resultsfit; merge results fit1;by n;
161 run;
162
163 data &output; set resultsfit;
164 drop n;
165 run;
166
167 %MEND REG2DSE;
168 %REG2DSE(y=DV, x=INDV, firm=firmid, time=timeid, multi=0, dataset=A.data, output=A.results);
MLOGIC(REG2DSE): Beginning execution.
MLOGIC(REG2DSE): Parameter Y has value DV
MLOGIC(REG2DSE): Parameter X has value INDV
MLOGIC(REG2DSE): Parameter FIRM has value firmid
MLOGIC(REG2DSE): Parameter TIME has value timeid
MLOGIC(REG2DSE): Parameter MULTI has value 0
MLOGIC(REG2DSE): Parameter DATASET has value A.data
MLOGIC(REG2DSE): Parameter OUTPUT has value A.results
NOTE: The data set WORK.FIT has 3 observations and 3 variables.
NOTE: The data set WORK.FIRM has 49 observations and 50 variables.
NOTE: PROCEDURE SURVEYREG used (Total process time):
real time 1.21 seconds
user cpu time 1.20 seconds
system cpu time 0.02 seconds
memory 11345.56k
OS Memory 40560.00k
Timestamp 29/05/2017 09:29:29 PM
Step Count 199 Switch Count 28
Page Faults 0
Page Reclaims 1998
Page Swaps 0
Voluntary Context Switches 72
Involuntary Context Switches 5
Block Input Operations 0
Block Output Operations 1080
 
 
NOTE: The data set WORK.TIME has 49 observations and 50 variables.
NOTE: PROCEDURE SURVEYREG used (Total process time):
real time 1.19 seconds
user cpu time 1.19 seconds
system cpu time 0.00 seconds
memory 5685.87k
OS Memory 41672.00k
Timestamp 29/05/2017 09:29:30 PM
Step Count 200 Switch Count 24
Page Faults 0
Page Reclaims 788
Page Swaps 0
Voluntary Context Switches 48
Involuntary Context Switches 2
Block Input Operations 0
Block Output Operations 920
 
 
MLOGIC(REG2DSE): %IF condition 0=1 is FALSE
MLOGIC(REG2DSE): %IF condition 0=0 is TRUE
WARNING: ODS graphics with more than 5000 points have been suppressed. Use the PLOTS(MAXPOINTS= ) option in the PROC REG statement
to change or override the cutoff.
NOTE: The data set WORK.PARM has 49 observations and 13 variables.
NOTE: The data set WORK.BOTH has 48 observations and 52 variables.
NOTE: PROCEDURE REG used (Total process time):
real time 2.20 seconds
user cpu time 2.18 seconds
system cpu time 0.02 seconds
memory 7661.12k
OS Memory 44996.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 201 Switch Count 37
Page Faults 0
Page Reclaims 1288
Page Swaps 0
Voluntary Context Switches 99
Involuntary Context Switches 5
Block Input Operations 0
Block Output Operations 7296
 
 
NOTE: There were 48 observations read from the data set WORK.BOTH.
NOTE: The data set WORK.BOTH has 48 observations and 53 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1085.31k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 202 Switch Count 20
Page Faults 0
Page Reclaims 285
Page Swaps 0
Voluntary Context Switches 32
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
 
NOTE: There were 48 observations read from the data set WORK.BOTH.
NOTE: The data set WORK.BOTH has 48 observations and 50 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1068.81k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 203 Switch Count 22
Page Faults 0
Page Reclaims 286
Page Swaps 0
Voluntary Context Switches 34
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
NOTE: There were 49 observations read from the data set WORK.PARM.
NOTE: The data set WORK.PARM has 49 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 1063.00k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 204 Switch Count 24
Page Faults 0
Page Reclaims 286
Page Swaps 0
Voluntary Context Switches 27
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
 
NOTE: There were 49 observations read from the data set WORK.PARM.
NOTE: The data set WORK.PARM1 has 49 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1057.31k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 205 Switch Count 22
Page Faults 0
Page Reclaims 288
Page Swaps 0
Voluntary Context Switches 35
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
NOTE: There were 49 observations read from the data set WORK.PARM1.
NOTE: The data set WORK.PARM1 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 1052.78k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 206 Switch Count 20
Page Faults 0
Page Reclaims 283
Page Swaps 0
Voluntary Context Switches 26
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
 
WARNING: The variable etf47 in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 48 observations read from the data set WORK.BOTH.
NOTE: The data set WORK.BOTH has 48 observations and 47 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 1079.50k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 207 Switch Count 28
Page Faults 0
Page Reclaims 284
Page Swaps 0
Voluntary Context Switches 42
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
 
NOTE: There were 49 observations read from the data set WORK.FIRM.
NOTE: The data set WORK.FIRM has 49 observations and 48 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1079.81k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 208 Switch Count 22
Page Faults 0
Page Reclaims 284
Page Swaps 0
Voluntary Context Switches 34
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
 
NOTE: There were 49 observations read from the data set WORK.TIME.
NOTE: The data set WORK.TIME has 49 observations and 48 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 1079.90k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 209 Switch Count 22
Page Faults 0
Page Reclaims 282
Page Swaps 0
Voluntary Context Switches 34
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
NOTE: There were 3 observations read from the data set WORK.FIT.
NOTE: The data set WORK.FIT1 has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1071.87k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 210 Switch Count 24
Page Faults 0
Page Reclaims 286
Page Swaps 0
Voluntary Context Switches 27
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
NOTE: There were 0 observations read from the data set WORK.FIT1.
NOTE: The data set WORK.FIT1 has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1058.09k
OS Memory 39336.00k
Timestamp 29/05/2017 09:29:33 PM
Step Count 211 Switch Count 20
Page Faults 0
Page Reclaims 286
Page Swaps 0
Voluntary Context Switches 26
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
 
 
NOTE: IML Ready
ERROR: (execution) Matrices do not conform to the operation.
 
operation : - at line 168 column 1
operands : _TEM1001, Z
_TEM1001 49 rows 48 cols (numeric)
Z 48 rows 47 cols (numeric)
 
statement : ASSIGN at line 168 column 1
ERROR: (execution) Matrix has not been set to a value.
 
operation : # at line 168 column 1
operands : C, B
C 49 rows 49 cols (numeric)
 
B 0 row 0 col (type ?, size 0)
 
 
statement : ASSIGN at line 168 column 1
ERROR: (execution) Matrix has not been set to a value.
 
operation : * at line 168 column 1
operands : E, D
 
E 0 row 0 col (type ?, size 0)
 
D 49 rows 1 col (numeric)
 
statement : ASSIGN at line 168 column 1
ERROR: (execution) Matrix has not been set to a value.
 
operation : ## at line 168 column 1
operands : F, *LIT1002
 
F 0 row 0 col (type ?, size 0)
 
 
*LIT1002 1 row 1 col (numeric)
 
0.5
 
statement : ASSIGN at line 168 column 1
ERROR: Matrix B has not been set to a value.
 
statement : PRINT at line 168 column 1
ERROR: Matrix G has not been set to a value.
 
statement : PRINT at line 168 column 1
ERROR: Matrix G has not been set to a value.
 
statement : CREATE at line 168 column 1
ERROR: No data set is currently open for output.
 
statement : APPEND at line 168 column 1
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 2.41 seconds
user cpu time 2.41 seconds
system cpu time 0.01 seconds
memory 3069.53k
OS Memory 41388.00k
Timestamp 29/05/2017 09:29:35 PM
Step Count 212 Switch Count 130
Page Faults 0
Page Reclaims 1369
Page Swaps 0
Voluntary Context Switches 503
Involuntary Context Switches 21
Block Input Operations 0
Block Output Operations 1376
 
 
ERROR: File WORK.B.DATA does not exist.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.RESULTS may be incomplete. When this step was stopped there were 0 observations and 5 variables.
WARNING: Data set WORK.RESULTS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 733.21k
OS Memory 39848.00k
Timestamp 29/05/2017 09:29:35 PM
Step Count 213 Switch Count 26
Page Faults 0
Page Reclaims 252
Page Swaps 0
Voluntary Context Switches 35
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
 
ERROR: BY variable n is not on input data set WORK.RESULTS.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.RESULTSFIT may be incomplete. When this step was stopped there were 0 observations and 5 variables.
WARNING: Data set WORK.RESULTSFIT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 1302.90k
OS Memory 40108.00k
Timestamp 29/05/2017 09:29:35 PM
Step Count 214 Switch Count 22
Page Faults 0
Page Reclaims 287
Page Swaps 0
Voluntary Context Switches 35
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
 
 
ERROR: Libref A is not assigned.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1033.12k
OS Memory 39588.00k
Timestamp 29/05/2017 09:29:35 PM
Step Count 215 Switch Count 20
Page Faults 0
Page Reclaims 248
Page Swaps 0
Voluntary Context Switches 26
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
 
MLOGIC(REG2DSE): Ending execution.
169
170 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
183
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The error is 

ERROR: (execution) Matrices do not conform to the operation.
 
One matrix has  49 rows 48 cols (numeric). The other has
                      Z 48 rows 47 cols (numeric)
 
So it would seem that your data is not the size that the macro expects. 

View solution in original post

5 REPLIES 5
ballardw
Super User

Did who ever wrot that macro provide any descriptions of what the input data set should look like? Does your data match those requirements?

 

 

Rick_SAS
SAS Super FREQ

The error is 

ERROR: (execution) Matrices do not conform to the operation.
 
One matrix has  49 rows 48 cols (numeric). The other has
                      Z 48 rows 47 cols (numeric)
 
So it would seem that your data is not the size that the macro expects. 
poulsinghps0
Calcite | Level 5

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)

 

 

Rick_SAS
SAS Super FREQ

After you run the macro, submit

 

proc print data=results; 
run;
poulsinghps0
Calcite | Level 5

That worked, thank you very much.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1663 views
  • 0 likes
  • 3 in conversation