wrds_guide.md (1383B)
1 # WRDS User Guide 2 3 4 ## Opening a WRDS connection 5 6 Since we are about to download data from CRSP we set up a connection with our WRDS credentials 7 ```julia 8 using FinanceRoutines 9 using DataFrames, Dates 10 using FixedEffectModels # for regressions 11 wrds_conn = FinanceRoutines.open_wrds_pg() 12 const date_init = Date("2010-01-01") 13 ``` 14 15 16 ## Download the monthly stock file from CRSP 17 18 19 Import the monthly stock file 20 ```julia 21 df_msf = import_MSF_v2(wrds_conn; date_range = (date_init, Dates.today())); 22 select!(df_msf, :permno, :mthcaldt=>:date, :datem, :mthret=>:ret, :mthcap) 23 ``` 24 25 If you are using the old SIZ MSF files 26 ```julia 27 # Import the monthly stock file 28 df_msf = import_MSF(wrds_conn; date_range = (Date("1980-01-01"), Dates.today())); 29 df_msf = build_MSF!(df_msf); # Run common processing 30 # keep only what we need from the MSF 31 select!(df_msf, :permno, :date, :datem, :ret, :mktcap) 32 ``` 33 34 35 ## Download the annual compustat funda file from WRDS 36 37 ```julia 38 df_funda = import_Funda(wrds_conn; date_range = (date_init, Dates.today())); 39 build_Funda!(df_funda); 40 ``` 41 42 ## Merge both files CRSP MSF and Compustat Funda 43 44 ```julia 45 df_linktable = FinanceRoutines.import_ccm_link(wrds_conn) 46 df_msf = link_MSF(df_linktable, df_msf) # merge gvkey on monthly stock file 47 # merge for a crsp/compustat merged file 48 df_ccm = innerjoin(df_msf, df_funda, on = [:gvkey, :datey], matchmissing=:notequal) 49 ``` 50