*Revised July, 2009;
*This pgm conducts study that addresses seasonality in the data;
*Newey-West autocor-adjusted std errors --using MODEL command;
PROC IMPORT OUT= WORK.seasonality
DATAFILE= "o:\pkoch\FIN 922\CP6_seasonality.July-2009\SeasonalityData.xls"
DBMS=EXCEL2000 REPLACE;
GETNAMES=YES;
RUN;
data seasonality; set WORK.seasonality;
logvn=log(v/n);
logypn=log(Y/(p*n));
i+1;
if month='Jan' then d1=1; else d1=0;
if month='Feb' then d2=1; else d2=0;
if month='Mar' then d3=1; else d3=0;
if month='Apr' then d4=1; else d4=0;
if month='May' then d5=1; else d5=0;
if month='Jun' then d6=1; else d6=0;
if month='Jul' then d7=1; else d7=0;
if month='Aug' then d8=1; else d8=0;
if month='Sep' then d9=1; else d9=0;
if month='Oct' then d10=1; else d10=0;
if month='Nov' then d11=1; else d11=0;
run;
proc print data=seasonality;
var logvn logypn d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11;
title 'seasonality study data';
run;
proc plot data=seasonality;
plot logvn*i;
title 'seasonality study data';
run;
*Newey-West autocorrelation-adjusted standard errors --using MODEL command;
proc model; *notice the proc model statement instead of proc reg;
parms b0 b1; *here, you need to define your parameters;
logvn = b0 + b1*logypn; *where logvn & logypn are the variables;
fit logvn /gmm kernel = QS; *********THIS asks for Newey-West adj;
instruments logypn; *here, list explanatory (RHS) variables in OLS model;
title 'Newey-West autocorrelation-adjusted std errors';
title2 'First Model: Unabridged -- no dummies';
run;
proc model;
parms b0 b1 c1-c11;
logvn = b0 + b1*logypn + c1*d1 + c2*d2 + c3*d3 + c4*d4 + c5*d5 + c6*d6
+ c7*d7 + c8*d8 + c9*d9 + c10*d10 + c11*d11;
fit logvn /gmm kernel = QS;
instruments logypn d1-d11;
title 'Newey-West autocorrelation-adjusted std errors';
title2 'Second Model: Unabridged -- dummies';
run;
*Create subsample that excludes 1st & last 6 months;
data seasonality_abridged;set seasonality;
if ((i>6) and (i<67));
run;
proc model data=seasonality_abridged;
parms b0 b1;
logvn = b0 + b1*logypn;
fit logvn /gmm kernel = QS;
instruments logypn;
title 'Newey-West autocorrelation-adjusted std errors';
title2 'First Model: Abridged -- no dummies';
run;
proc model data=seasonality_abridged;
parms b0 b1 c1-c11;
logvn = b0 + b1*logypn + c1*d1 + c2*d2 + c3*d3 + c4*d4 + c5*d5 + c6*d6
+c7*d7 + c8*d8 + c9*d9 + c10*d10 + c11*d11;
fit logvn /gmm kernel = QS;
instruments logypn d1-d11;
title 'Newey-West autocorrelation-adjusted std errors';
title2 'Second Model: Abridged -- dummies';
run;
********************************************************;
title 'Seasonally adjusting with Commerce Dept approach';
data seasonality;set seasonality;
vL1=lag1(v);vL2=lag2(v);vL3=lag3(v);
vL4=lag4(v);vL5=lag5(v);vL6=lag6(v);
vL7=lag7(v);vL8=lag8(v);vL9=lag9(v);
vL10=lag10(v);vL11=lag11(v);vL12=lag12(v);
run;
data seasonality;set seasonality;
cma=(.5*vL12+vL11+vL10+vL9+vL8+vL7+vL6+vL5+vL4+vL3+vL2+vL1+.5*v)/12;
rcmaL6=vL6/cma;
*this is rcma, but it begins 6 months too late in December rather than June;
run;
*need to adjust the rcma series to move FORWARD in time 6 months,
so that it begins in June 1971 rather than in Dec 1971;
proc sort data=seasonality;by descending i;run;
*the word, descending, asks sas to sort in reverse order;
*after that, can use lag command to move the rcmaL6 series FORWARD 6 months;
data seasonality;set seasonality;
rcma=lag6(rcmaL6); *this line shifts the rcma series FORWARD to begin in June;
run;
*Now re-sort in ascending order;
proc sort data=seasonality;by i;run;
*now get means of rcma by month;
data seasonality;set seasonality;
if (month='Jan') then mon=1;
if (month='Feb') then mon=2;
if (month='Mar') then mon=3;
if (month='Apr') then mon=4;
if (month='May') then mon=5;
if (month='Jun') then mon=6;
if (month='Jul') then mon=7;
if (month='Aug') then mon=8;
if (month='Sep') then mon=9;
if (month='Oct') then mon=10;
if (month='Nov') then mon=11;
if (month='Dec') then mon=12;
run;
proc sort data=seasonality;by mon;run;
proc univariate data=seasonality noprint;
var rcma;
output out=seasonal_adj_factors
mean=rcma_bar;
by mon;
run;
*the statement, by mon, asks sas to compute the means for each month;
*the statement, output, asks sas to output the means for each month,
to a new dataset called seasonal_adj_factors;
proc print data=seasonal_adj_factors;
title 'Seasonally adjusting with Commerce Dept approach';
title2 'RCMA_BAR = Seasonal Adjustment Factors';
run;
*Now merge seasonal adj factors (rcma_bar) back into dataset;
proc sort data=seasonal_adj_factors;by mon;run;
data seasonality;set seasonality;
merge
seasonality (in=A)
seasonal_adj_factors
;
if A;
by mon;
run;
*Now that rcma_bar is in dataset, can create seasonally adj visits, SAV;
proc sort data=seasonality;by i;run;
data seasonality;set seasonality;
sav=v/rcma_bar;
logsavn=log(sav/n);
run;
*Note: this generates obs for SAV for all 72 data points
But the RCMA_BAR series really only applies to 60 data points,
beginning in July 1971 and ending in June 1976,
since the first & last 6 months are lost in generating CMA;
*Run regression using SAV, using all 72 data points (unabridged sample);
proc model data=seasonality;
parms b0 b1;
logsavn = b0 + b1*logypn;
fit logsavn /gmm kernel = QS;
instruments logypn;
title 'Seasonally adjusting with Commerce Dept approach ';
title2 'Using Seasonally Adjusted Visits (SAV) in Regresion';
title3 'Newey-West autocorrelation-adjusted std errors ';
title4 'First Model: UnAbridged (all 72 obs) -- no dummies ';
run;
*Re-run regression with SAV, using just the correct 60 data points;
data seas_abridge;set seasonality;
if (i>6) and (i<67);
run;
proc model data=seas_abridge;
parms b0 b1;
logsavn = b0 + b1*logypn;
fit logsavn /gmm kernel = QS;
instruments logypn;
title 'Seasonally adjusting with Commerce Dept approach ';
title2 'Using Seasonally Adjusted Visits (SAV) in Regresion';
title3 'Newey-West autocorrelation-adjusted std errors ';
title4 'First Model: Abridged -- (60 obs) -- no dummies ';
run;
quit;