Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About link compustat and crsp by python #1

Closed
kite8 opened this issue Feb 28, 2019 · 2 comments
Closed

About link compustat and crsp by python #1

kite8 opened this issue Feb 28, 2019 · 2 comments
Labels
question Further information is requested

Comments

@kite8
Copy link

kite8 commented Feb 28, 2019

I have two questions I would like to ask you. Thanks.

  1. How to match CRSP monthly with Compustat quarterly through python?
    Is like this ?
# Get a comp demo data
comp_demo = db.get_table(library='comp', table='funda', columns=['gvkey', 'datadate',
                                                                'fyear'])
comp_demo.drop_duplicates(inplace=True)

# Get a CRSP demo data
crsp_demo = db.get_table(library='crsp', table='msf', columns=['permno', 'ncusip', 'date'])
crsp_demo.drop_duplicates(inplace=True)

# Get Compustat-CRSP linktable
link = db.get_table(library='crsp', table='ccmxpf_lnkhist', columns=['gvkey', 'lpermno', 'lpermco', 'linktype', 'linkprim']) # 'linkdt', 'linkenddt'
link = link[link['linktype'].isin(['LC', 'LU'])]
link = link[link['linkprim'].isin(['C', 'P'])]
link.drop(['linktype', 'linkprim'], axis=1, inplace=True)

crsp_add_gvkey = crsp_demo.merge(link, left_on='permno', right_on='lpermno')
crsp_add_gvkey.drop_duplicates(inplace=True)

out = crsp_add_gvkey.merge(comp_demo, left_on='gvkey', right_on='gvkey')
out.drop_duplicates(inplace=True)
  1. how to resample the data by fiscal year ?
@snauhaus
Copy link
Owner

snauhaus commented Mar 13, 2019

Hey,

The link tables just help match the correct firms to each other. To match the dates, be it months, quarters, or years, you need to create a matching date variable in both datasets. Then, to aggregate, use whatever statistic makes sense to you. I used the median CRSP forecast as that seemed to be common in the literature.

Hope that helps!

@kite8
Copy link
Author

kite8 commented Mar 13, 2019

Thank you very much!
I had succeed in linking table.

@snauhaus snauhaus added the question Further information is requested label Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants