- At minimum, you need SICH, SALE, and FYEAR from COMPUSTAT.
- SICH is four digits. As an example, if you want to compute HHI by three-digit SIC, do the following:
char_sic=put(sich,4.0);*This converts SICH from numeric to character; three_char_sic=substr(char_sic,1,3);*This takes the first three components of the string; sicthree=input(three_char_sic,best3.);*This converts the character back;
- We first need to compute the total size of the market for a given industry-year:
proc summary data=sic; by sicthree fyear; var sale; output out=hhidenom (drop=_type_ _freq_) sum=; run;
- Now, we can compute the HHI:
*Sort before merge; proc sort data=sic; by sicthree fyear; run; proc sort data=hhidenom; by sicthree fyear; run;
*Merge denominator; proc sql;*http://sbaleone.bus.miami.edu/PERLCOURSE/SASFILES/SQL_EXAMPLES.sas; create table compstatdenom as select a.*, b.sale as denom from sic a left join hhidenom b on (a.sicthree=b.sicthree) and (a.fyear=b.fyear); quit;
*Create market share; data compstatshare; set compstatdenom; share=sale/denom; sharesq=share**2; run;
*Create HHI; *http://www.talkstats.com/showthread.php/10892-Sum-up-values-by-groups; proc summary data=compstatshare; by sicthree fyear; var sharesq; output out=sumhhi (drop=_type_ _freq_) sum=; run;
*Merge HHI; proc sql;*http://sbaleone.bus.miami.edu/PERLCOURSE/SASFILES/SQL_EXAMPLES.sas; create table compstathhi as select a.*, b.sharesq as hhi from compstatshare a left join sumhhi b on (a.sicthree=b.sicthree) and (a.fyear=b.fyear); quit;
Tuesday, February 19, 2013
Steps to compute HHI in SAS
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment