Hello! It is my first question on this forum, thanks for the patience and help.
I have a panel data for stock returns 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. I want to check if firms have at least 30 days of activity within an year (at least 30 non-blank and non-zero number of trades data points for each firm-year combination). If the firm-year does not pass the check, meaning it does not have at least 30 non-blank non-zero number of trades, I want to remove all the observations for that entire firm-year.
I have been trying to write a DO loop for this, but to be honest I'm not very experienced and I could not accomplish this task.
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 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 measure.
Thanks,
Lucas Balaminut