- 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
Monday, April 09, 2012
Dates in SAS
Suppose you imported data from a spreadsheet with dates that look like 20120409. How can you convert them to the familiar date9 format in SAS?
If they are already in character format, do the following:
Take care to replace the mmddyy8. depending on how the date is initially written.
If they are in numeric format, then do the following:
That is, you first convert numeric to character and then character to date. Be sure to keep in mind that this process is vastly made easier if you take care to input the dates in a "nice" format to begin with in the spreadsheet.
Monday, January 16, 2012
How do I identify runs of consecutive observations in panel data?
The STATA mailing list has a way to identify runs of consecutive observations. With some googling, SAS can do the same thing. Here's how.
Suppose you want to figure out how many observations you have per GVKEY:
Monday, November 21, 2011
Merging with CIK
CIKs are 10-digit characters, but if you manually code them from EDGAR, they won't have leading zeroes. So use "z10."
Tuesday, October 11, 2011
Averages across years
PROC MEANS nolabel DATA=[dataset] ;
CLASS [year];
VAR [variable];
OUTPUT OUT=[dataset] MEAN= ;
RUN;
MEAN can be replaced by MEDIAN.
Sunday, October 09, 2011
Esttab and multiple dummy indicators
Suppose your empirical specification has both unit and time fixed effects. You don't the table to be cluttered with n or m variables, do you?
Including indicate("Time fixed effects = " "Unit fixed effects = ") after esttab will do the trick. Note the STATA output to determine what to put after the equal signs.
Ado Path
Emerald at UNC has STATA 11.2 but is not cooperative when it comes to downloading *.ado files (e.g. estout). So I downloaded estout in STATA 9.2 through Latte at Fuqua and then copied the folder to my Emerald account. Do note that you must use "scp" and not "sftp" due to the latter's restriction on recursive copying (i.e. folders).
The help for adopath suggested that the folder be copied to the "/netscr/[username]" folder. After that, esttab worked just fine.
Thursday, September 22, 2011
Destringing GVKEY
GVKEY as-is from COMPUSTAT in WRDS comes as a string variable. To destring it in STATA, type
To destring it in SAS, a ghetto way is to multiply it by 1.
Friday, July 22, 2011
Converting from 4-Digit SIC to 2-Digit SIC
Table 4 of "The power of the pen and executive compensation" (Core, Guay, and Larcker 2008) contains "fixed effects for year and 2-digit SIC codes." But ExecuComp in WRDS gives you the 4-digit SIC codes. How do you get from 4 digits to 2 in SAS?
First, note that the first two digits denote the "major industry group." Second, 4-digit SIC from ExecuComp is unsurprisingly numeric. So substr won't work unless you first convert from numeric to string:
Then you can use substr. Just be sure to convert it back to numeric:
Now run your fixed effects regression.
Monday, November 29, 2010
Matrices in MATLAB
Let X be some matrix. Then, X(:,i) will give you the i-th column with all the rows, and X(i,:) will give you the i-th row with all the columns.
Monday, August 16, 2010
Flash Drives
If you're having problems figuring out what your flash drive is called in Arch Linux, less /var/log/messages.log. Life saver.
Wednesday, April 28, 2010
How to win CapSim
If you want to do well in the CapSim part of your strategic management class, you have to be willing to put in the hours. Some of our classmate competitors did not realize how much effort my teammate and I put in; we individually logged in more than many other teams did collectively. We viewed the CapSim as an enjoyable game; when other Georgia Tech students played WoW or LoL, we played CapSim.
Do the situation analysis online, but don't forget that your demand analysis should be based on what is in the Round 0 edition of the CapStone Courier. Moreover, don't forget that each segment has a different growth rate. I made the previous mistake TWICE, which cost my team lost profit. Luckily, we never turned a loss, and we never made any mistakes after Round 3.
If you start a price war, don't raise your price! Following this piece of advice could've saved us $18,000,000 in an emergency loan as well as given us twenty additional points for the final balanced scorecard.
Read the CapStone Courier cover to cover. It contains all the competitive intelligence you need to defeat your competitors. Be sure to pay attention to the production analysis page; there is a lot of information on that single page alone. In particular, take note of whether any of your competitors is launching a new product.
Read the manual cover to cover. There is a plethora of information regarding pricing, budgeting for sales and promotion, human resources, finance, and so forth. Moreover, if your professor has activated advanced modules, then read the accompanying descriptions online word for word. The additional information for TQM explicitly stated that $1,500,000 was the magic number: you got the most bang for your buck with that investment. Yet, in what I can only describe as evidence of the failure of the "divide and conquer" strategy, one of our competitors put in a total of $8,000 the first round TQM was on. That team already lost money in that round; their TQM investment gave them no return and served only to put them $8,000 more in the red.
Invest in automation and TQM. The manual describes the pitfalls of automation, but if TQM is activated, you can invest in the initiatives that reduce R&D cycle time, negating the major drawback of automation (ie. increased R&D cycle time). Automation reduces your labor costs as well as the needed complement. We invested in automation so thoroughly that during the second labor negotiation, we caused all but one of our competitors to strike for the maximum length. We also invested in TQM earlier on so we didn't have to do it later on. Toward the end, automation and TQM had reduced our costs to the point where we sold more products than the competition at lower costs.
Invest in human resources. A higher productivity index means you can get the same output with fewer workers or more output with the same amount. You can taper off your expenditures in later rounds without hurting your productivity index, though your turnover rate may never be low enough to get you full points in the balanced scorecard. Many of our competitors made no investment in HR when the module was first activated. Consequently, they were never able to catch up to our productivity index increase.
Pay attention to advanced marketing, if it is activated. It makes getting full awareness and full accessibility MUCH harder, if not downright impossible. Again, many of our competitors did not pay any attention to advanced marketing and saw precipitous declines in their awareness and accessibility. Ours declined as well but not by nearly as much.
Saturday, January 16, 2010
Multi-monitor update
Due to winter break, I had not updated my Archlinux install for about a month. During that time, there appeared to have been several major changes, including a kernel update as well as an Xorg update.
When I rebooted, I found that my multi-monitor setup was borked. It was doing a very bad job of mirroring the displays when I wanted them to be extended.
It turns out that the Xorg update changed the reference names for the monitors. VGA and LVDS are now VGA1 and LVDS1, respectively. A bit of playing around with xrandr in the command line solved that nicely, though I admit I was in a panic and ready to ask the forums for advice.
Monday, June 08, 2009
TrackPoint Scroll
This works for my Lenovo ThinkPad R61 (7732-CTO) running Archlinux.
Create a file in /etc/hal/fdi/policy called mouse-wheel.fdi with the following:
<match key="info.product" string="TPPS/2 IBM TrackPoint">>
<merge key="input.x11_options.EmulateWheel" type="string">>true</merge>>
<merge key="input.x11_options.EmulateWheelButton" type="string">>2</merge>>
<merge key="input.x11_options.YAxisMapping" type="string">>4 5</merge>>
<merge key="input.x11_options.XAxisMapping" type="string">>6 7</merge>>
<merge key="input.x11_options.Emulate3Buttons" type="string">>true</merge>>
<merge key="input.x11_options.EmulateWheelTimeout" type="string">>200</merge>>
</match>>
Kindly ignore the duplicate tags.
Now, if you click and hold the middle mouse button, you can use the TrackPoint to scroll vertically and horizontally. As of June 8, 2009, I am still unable to get my touchpad to work ><
Sunday, February 15, 2009
ksh PS1 and reloading .profile
OpenBSD comes with a plain "$" prompt in the shell. To spice things up, enter the following in your .profile:
PS1="\u@\h:\w$ "; export PS1
This will give username@host:PWD$.
To reload the .profile after making these changes, type the following:
. $HOME/.profile
There is a space after the first dot. Source
Friday, January 09, 2009
SCIM in OpenSolaris
Add the following two lines to your $HOME/.profile file:
GTK_IM_MODULE=scim
export GTK_IM_MODULE
Flash Player 10 on OpenSolaris
- Download the .tar.bz2 file from Adobe.
- bunzip2 [name of file]
- tar -xvf [name of file]
- cd [name of directory]
- cp libflashplayer.so /usr/lib/firefox/plugins
- Restart Firefox
Wednesday, December 17, 2008
Helpful commands for R
- library(foreign) - Allows you to load Stata and Excel files, among others.
- foo <- read.dta("location") - Loads a Stata *.dta file.
- names(foo) - Lists the names of the variables in dataset foo.
- fit <- lm(y~x,data="foo") - Linear regression of Y on X using data in foo.
- fit <- glm(y~x,family=binomial(link="probit"),data="foo") - Probit regression of Y on X using data in foo.
- summary(fit) - The stuff you want in model fit.
Friday, December 12, 2008
Importance of reading manual pages (wireless)
I had some difficulty configuring wireless at Georgia Tech for OpenBSD, but it was only because of my failure to read the manual pages carefully.
Under the nwkey entry of ifconfig(8), "The key can either be a string, a series of hexadecimal digits (preceded by '0x')..." (emphasis mine). Obviously, if there is no '0x', then ifconfig assumes your WEP key is a string. In our school's case, the WEP key is hexadecimal.
Wednesday, December 10, 2008
VIm and Arrow Keys
For some reason, using arrow keys in VIm is equivalent to typing ABCD. A temporary fix is to type :set term=cons25.