This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Export of SAS dataset to Mongodb | |
*/ | |
/* References to project folders */ | |
%let projectDir = E:\research\projects\myProject\; | |
%let mongoExportDir = &projectDir.sas\export to mongo\; | |
/* Path to Mongoimport executable */ | |
%let mongoimportPath = 'C:\Program Files\MongoDB\Server\3.0\bin\mongoimport.exe'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Retrieve variables in Funda */ | |
ods listing close; | |
ods output variables = varsFunda; | |
proc datasets lib = comp; contents data=funda; quit;run; | |
ods output close; | |
ods listing; | |
/* keep relevant variables (excluding firm name, gvkey, fyear, etc)*/ | |
data varsFunda ; | |
set varsFunda; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Making macro variables available on remote server with syslput */ | |
/* login to remote server */ | |
%let wrds = wrds.wharton.upenn.edu 4016;options comamid = TCP remote=WRDS; | |
signon username=_prompt_; | |
/* this macro retrieves Compustat Funda variables from year1 to year2 */ | |
%macro getFunda(dsout=, year1=2010, year2=2013, vars=); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* IBES: number of analysts | |
*/ | |
data a_funda (keep = key gvkey fyear datadate conm); | |
set comp.funda; | |
/* limit to firms with more than $20 mln sales and fiscal years 2010-2012 */ | |
if sale > 20; | |
if 2010 <= fyear <= 2012; | |
/* create key to uniquely identify firm-year */ | |
key = gvkey || fyear; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* macro that retrieves permno for Compustat records | |
dsin: dataset to append permno to, required variables: gvkey, and a date variable | |
dsout: dataset to create | |
datevar: name of date variable (e.g. datadate, or event date) | |
sample use: %getPermno(dsin=a_mydata, dsout=b_withpermno, datevar=datadate); | |
*/ | |
%macro getPermno(dsin=, dsout=, datevar=); | |
proc sql; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* requires sorting */ | |
proc sort data = myData; by gvkey;run; | |
/* glm */ | |
proc glm data = myData; | |
absorb gvkey; | |
ods output ParameterEstimates = work.params | |
FitStatistics = work.fit | |
NObs = work.obs; | |
model depvar = indep1 indep2 / solution ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data returns; | |
input @01 id | |
@03 date MMDDYY10. | |
@14 return; | |
format date date9.; | |
datalines; | |
1 10/31/2013 0.01 | |
1 11/30/2013 0.02 | |
1 12/31/2013 0.03 | |
1 01/31/2014 -0.01 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data ratingdata; | |
input @01 id 1. | |
@03 startyr 4. | |
@08 endyr 4. | |
@13 rating $1. | |
; | |
datalines; | |
1 2002 2004 A | |
1 2005 2007 A | |
1 2007 2009 B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | rating_combined | start_combined | end_combined | |
---|---|---|---|---|
1 | A | 2002 | 2007 | |
1 | B | 2007 | 2009 | |
1 | A | 2009 | 2010 | |
2 | A | 2002 | 2004 | |
3 | B | 2001 | 2007 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Retrieve historic cusip | |
work.myDset holds permno and datadate (end of fiscal year) | |
Appends historic cusip (at time datadate) | |
*/ | |
proc sql; | |
create table work.withCusip as | |
select a.*, b.ncusip | |
from work.myDset a, crsp.dsenames b | |
where | |
a.permno = b.PERMNO |
NewerOlder