Friday, October 21, 2005

Super Cool Matching Code By Franco, Cassar, and Center-Zechman

Here’s a matching program where I matched on industry (the barth, beaver, landsman 15 industry codes), the existence of disclosure variables, the period in time as I had floating windows and all firm within the upper and lower bounds. After running this program, you just need to determine which of the firms meeting the criteria to keep as there are likely several firms for each sample firm within the upper and lower bounds. What I did was to calculate |diff|=sample(nidiff_assets)- match(nidiff_assets) and keep the absolute closest making sure not to keep duplicate matches.



Props to Aunt Fran for the underlying code!
...and Gavin for the 0.01 innovation.



%LET max = 1.50;

%LET min = 0.50;



*set the upper bound as the greater of variable*max(above) and variable+0.01;

max1=&max*nidiff_assets;

max2=nidiff_assets+0.01;

if nidiff_assets=. then max=.;

else if max1>max2 then max=max1;

else if max2>=max1 then max=max2;

else max=.;



*set the lower bound as the lesser of variable*min(above) and variable-0.01;

min1=&min*nidiff_assets;

min2=nidiff_assets-0.01;

if nidiff_assets=. then min=.;

else if min1
else if min2<=min1 then min=min2;

else min=.;



DATA temp; SET temp;

RENAME nidiff_assets=nidiffasset_sample;



PROC SQL;

CREATE TABLE temp1 AS SELECT

temp.*, match_comp_ind.gvkey, match_comp_ind.industry, match_comp_ind.pre_beg, match_comp_ind.flg_file,

match_comp_ind.flg_call, match_comp_ind.flg_ratio, match_comp_ind.nidiff_assets, match_comp_ind.assets,

match_comp_ind.sum_diff, match_comp_ind.filings_diff, match_comp_ind.calls_diff, match_comp_ind.sic,

match_comp_ind.rev_ratio_diff

FROM temp, mydata.match_comp_ind

WHERE temp.pre_beg_sample=match_comp_ind.pre_beg AND

temp.industry_sample=match_comp_ind.industry AND

temp.flg_file_sample=match_comp_ind.flg_file AND

temp.flg_call_sample=match_comp_ind.flg_call AND

temp.flg_ratio_sample=match_comp_ind.flg_ratio AND

temp.min <= match_comp_ind.nidiff_assets <= temp.max;

QUIT;

Saturday, August 13, 2005

Industry Codes (taken from US Census Site)

Here are 19 industry codes (which Core-Guay 99 use, at least that's what the US Census uses) ;) http://www.census.gov/epcd/www/naicsect.htm

NOTE: since I exclude financial firms as did Core Guay 99, there is no dummy variable for NAICS sector 52, if youi are including it, make sure to add the appropriate dummy variable. :)

/********************************************/
/* NEED TO ADD 19 Industry indicators */
/********************************************/

/*
Code NAICS Sectors
11 Agriculture, Forestry, Fishing and Hunting
21 Mining
22 Utilities
23 Construction
31-33 Manufacturing
42 Wholesale Trade
44-45 Retail Trade
48-49 Transportation and Warehousing
51 Information
52 Finance and Insurance
53 Real Estate and Rental and Leasing
54 Professional, Scientific, and Technical Services
55 Management of Companies and Enterprises
56 Administrative and Support and Waste Management and Remediation Services
61 Education Services
62 Health Care and Social Assistance
71 Arts, Entertainment, and Recreation
72 Accommodation and Food Services
81 Other Services (except Public Administration)
92 Public Administration
*/

DATA temp;
SET temp;
x = ROUND(NAICS/10000);
IF x = 11 THEN ID1 = 1; ELSE ID1 = 0;
IF x = 21 THEN ID2 = 1; ELSE ID2 = 0;
IF x = 22 THEN ID3 = 1; ELSE ID3 = 0;
IF x = 23 THEN ID4 = 1; ELSE ID4 = 0;
IF x in (31,32,33) THEN ID5 = 1; ELSE ID5 = 0;
IF x = 42 THEN ID6 = 1; ELSE ID6 = 0;
IF x in (44,45) THEN ID7 = 1; ELSE ID7 = 0;
IF x in (48,49) THEN ID8 = 1; ELSE ID8 = 0;
IF x = 51 THEN ID9 = 1; ELSE ID9 = 0;
IF x = 53 THEN ID10 = 1; ELSE ID10 = 0;
IF x = 54 THEN ID11 = 1; ELSE ID11 = 0;
IF x = 55 THEN ID12 = 1; ELSE ID12 = 0;
IF x = 56 THEN ID13 = 1; ELSE ID13 = 0;
IF x = 61 THEN ID14 = 1; ELSE ID14 = 0;
IF x = 62 THEN ID15 = 1; ELSE ID15 = 0;
IF x = 71 THEN ID16 = 1; ELSE ID16 = 0;
IF x = 72 THEN ID17 = 1; ELSE ID17 = 0;
IF x = 81 THEN ID18 = 1; ELSE ID18 = 0;
IF x = 92 THEN ID19 = 1; ELSE ID19 = 0;
RUN;

Friday, August 12, 2005

How To MERGE with KEEP and IN

The following SAS code lets you MERGE two datasets whil only pulling the variables that you want from the larger dataset (in this case, crspq.msi) by the variable "date" and the "IF m=1" ensures that any merging will only occur on items on the delist1 dataset (meaning that the sample size of delist1 will remain the same):


DATA delist1;
MERGE delist1(IN=m) crspq.msi(IN=q KEEP= date ewretd);
BY date;
IF m=1;
RUN;