I am new to STATA and run into a problem with my dataset which contains companies stock information from 2004 to 2018 .The variables included are permno (company id), date, closing_price (stock price) and Dummy. I would like to eliminate stocks with closing prices less than $5. In the attached data example I generated a dummy variable = 1 if the stock price is below $5. However, it can be the case that the stock price drops below $5 only once or twice (see permno 10078). Nevertheless, I would like to drop the whole company out of my dataset and not just the one observation. The command: tab permno if Dummy == 1, lists all permno's that should be deleted. Is there a way to save this list and use it to delete all companies on it? Writing down every permno manually is not an option as the original dataset is much larger.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date float(closing_price Dummy) 10042 16072 3.75 1 10042 16075 4.02 1 10042 16076 3.98 1 10042 16077 3.97 1 10042 16078 4.05 1 10042 16079 4.22 1 10042 16082 4.62 1 10042 16083 4.3 1 10042 16084 3.85 1 10042 16085 3.82 1 10042 16086 3.88 1 10042 16090 3.97 1 10042 16091 3.85 1 10042 16092 3.7 1 10042 16093 3.55 1 10042 16096 3.41 1 10042 16097 3.69 1 10042 16098 3.86 1 10042 16099 3.75 1 10042 16100 3.7 1 10044 16072 12.29 . 10044 16075 12.03 . 10044 16076 11.68 . 10044 16077 11.96 . 10044 16078 14.25 . 10044 16079 14.75 . 10044 16082 14.561 . 10044 16083 14.35 . 10044 16084 14.25 . 10044 16085 14.25 . 10044 16086 14.25 . 10044 16090 14.25 . 10044 16091 14.249 . 10044 16092 14.22 . 10044 16093 14.2377 . 10044 16096 14.24 . 10044 16097 14.25 . 10044 16098 14.08 . 10044 16099 14.239 . 10044 16100 14.35 . 10051 16072 15.67 . 10051 16075 15.7 . 10051 16076 15.85 . 10051 16077 15.69 . 10051 16078 15.83 . 10051 16079 16 . 10051 16082 16.5 . 10051 16083 16.34 . 10051 16084 16.6 . 10051 16085 17.58 . 10051 16086 18.08 . 10051 16090 18.3 . 10051 16091 19.06 . 10051 16092 18.72 . 10051 16093 18.66 . 10051 16096 18.83 . 10051 16097 18.7 . 10051 16098 18.71 . 10051 16099 18.7 . 10051 16100 18.75 . 10056 16072 29.091 . 10056 16075 29.18 . 10056 16076 29.35 . 10056 16077 29.26 . 10056 16078 28.77 . 10056 16079 28.66 . 10056 16082 28.66 . 10056 16083 28.66 . 10056 16084 28.75 . 10056 16085 28.92 . 10056 16086 28.97 . 10056 16090 29.21 . 10056 16091 29.35 . 10056 16092 29.05 . 10056 16093 29.4 . 10056 16096 29.46 . 10056 16097 29.36 . 10056 16098 29.11 . 10056 16099 28.4 . 10056 16100 28.65 . 10078 16072 4.7 1 10078 16075 4.7 1 10078 16076 5.03 . 10078 16077 4.99 1 10078 16078 5.51 . 10078 16079 5.31 . 10078 16082 5.45 . 10078 16083 5.5 . 10078 16084 5.46 . 10078 16085 5.36 . 10078 16086 5.39 . 10078 16090 5.59 . 10078 16091 5.663 . 10078 16092 5.52 . 10078 16093 5.45 . 10078 16096 5.61 . 10078 16097 5.55 . 10078 16098 5.473 . 10078 16099 5.23 . 10078 16100 5.287 . end format %td date
Thank you very much!
Max
0 Response to Drop all observations of a company if it does not meet the requirement at one point in time
Post a Comment