I need to create a variable to caputure firm-level seasonally adjusted asset growth rate volatility . I use the following to code to capture the volatility ( I didn't adjust seasonal factor). Can someone let me know if this code is ok or there is some better code to do it?? Also, could someone let me know how to seasonally adjusted the volatility?? I have no clue.
proc sort data=HAVE;
by company_ID date_quarterly;
run;
proc expand data=HAVE out=WANT method=none;
convert asset_growthrate=asset_growthrate_std / transformout=(movstd 8);
by company_ID;
run;
You have in effect three variables (asset_growthrate_std, company_id date_quarterly, with four records per company_id/year, sorted by company_id/date_quarterly. The question is what sample do you want to use for determining seasonality? (1) Do you want to use your entire date range?
I'm going to assume that (1) you're going to use your entire sample of companies over all your sample date range (I'll assume 1981 through 2010, i.e. 30 year ==> 120 quarters). And I'll assume that you'll be interested in the seasonality indexes averaged over all the years - i.e. each year is weighted equally. And since the item of interest is a rate, I'll assume all companies are equally weighted for each yearly result.
This program does that:
Notes:
data want (keep=seasonal_index1-seasonal_index4);
set have end=end_of_have;
array qsums{1981:2010,1:4} _temporary_ (120*0);
qsums{year(date_quarterly),qtr(date_quarterly)}+asset_growthrate;
/* Get average over years of quartely shares*/
array seasonal_index {4} seasonal_index1-seasonal_index4 (4*0);
if end_of_have then do;
do year=1981 to 2010;
yearly_total=sum(qsums{year,1},qsums{year,2},qsums{year,3},qsums{year,4});
do q=1 to 4;
seasonal_index{q}=seasonal_index{q} + qsums{year,q}/(yearly_total/4);
end;
end;
do q=1 to 4;
seasonal_index{q}=seasonal_index{q}/dim(qsums,1);
end;
output;
end;
run;
Regards,
Mark
And (editted later) here's how to use the index to get adjusted rates (i.e. what the yearly rate would be based on a seasonally-adjusted modification of the observed quarterly rate:
data adjusted_rates (drop=seasonal_index1-seasonal_index4);
if _n_=1 then set want;
array seasonal_index {4} seasonal_index1-seasonal_index4;
set have;
adjusted_rate=asset_growthrate/seasonal_index{qtr(date_quarterly)};
run;
MK
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.