BookmarkSubscribeRSS Feed
OceanDream
Fluorite | Level 6

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;

1 REPLY 1
mkeintz
PROC Star

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:

  1. The two dimension array QSUMS has a row for each year from 1981 to 2010, and a column for each quarter.  It gets the total asset_growthrate over all companies for the given year/quarter.
  2. The program assumes that for each year, a company's quarterly data are complete.  I.e. a company may have data just for some years, but for those years in which it is present, it has data for all 4 quarters.
  3. Note this program makes no assumptions about year-to-year trends.
  4. The DIM(qsums,1) says to get the size of the first dimension of the qsums array, i.e. the number of rows in the array.

 


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

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 975 views
  • 0 likes
  • 2 in conversation