I have a panel data for stock returns, at the daily level, with the following variables: firm, year, day, return, and number of trades. I'm trying to remove observations based on on the number of trades variable.
Criteria: I want to check firms that have at least 30 days of trading activity within an year, that is, at least 30 non-blank and non-zero number of trades data points for each firm-year combination.
If a firm-year do pass the criteria, meaning it has at least 30 days with non-zero non-blank data points on the number of trades column, I want to keep all daily observations for that firm-year.
If I firm-year does not pass the criteria, I want to remove all the daily observations for that firm-year. Just to clarify: if a firm has an year for which it does not pass the criteria, but other years that do pass the criteria, I want to remove only the daily observations for that particular year that did not pass the criteria.
I have been trying to write a code for this, but to be honest I'm not very experienced and I could not accomplish this task. If anyone could help, it would be greatly appreciated!
Extra context: I'm using Compustat (compd.funda) merged with CRSP (crspa.dsf) through a link table (crsp.ccmxpf_linktable) to attempt to recreate a measure from Chen, Goldstein and Jiang, 2007 called R^2. This measure is from a regression of daily firm returns on market returns and industry returns. The authors filter the data by removing firm-year observations with less than 30 days of trading activities in a year, and I'm struggling to replicate this filter.
Thanks,
Lucas Balaminut
Related Posts with Removing observations based on a sequence of observations within a group
Generalized DiD: How will the regression equation look like?Hi guys, I´m setting up an generalized DiD model. The policy is adopted at different times (two dif…
Creating an indicator variable from multiple, non-mutually exclusive, dummy variablesHi! I'm trying to create an indicator variable from several dummy variables (which are not mutually …
Merging conditional on one range of dates falling within another range of datesHi. I have two sets of data, set 1 with variables HDR_startdate and HDR_enddate, and set 2 with vari…
Help with Stata Coding (Urgent!)Nothing …
PSID - Generating a household IDI am using 10 waves of the PSID data with the aim of analysing trends in household charitable giving…
Subscribe to:
Post Comments (Atom)
0 Response to Removing observations based on a sequence of observations within a group
Post a Comment