Hi,
I am using STATA version 16 and would need some help in counting the maximum number of observation before and after a specific value in a column.
Array
As you can see in the image above, the column "pt_output" has values 1 and 2. "1" represents the star of a recession and "2" represents the end of a recession. I want to know what is the maximum number of quarters before the value "1" and after the value "1".
My code for calculating quarters before value "1":
. count if id < 21
20
. count if id < 36
35
Then I will see that 35 is the maximum number of observations before a specific value. Is there a more efficient way of doing this? There is a lot of looking at the data to find out which id to choose from before setting up the code. Any help would be appreciated. Thanks!
Related Posts with Efficient way to calculate maximum number of observations before and after a specific value in a column
setstars option with asdocIn the (wonderful) asdoc program, the option setstars(*@.05, ~@.10) does not seem to work with neste…
How to construct equal weighted portfolio using StataHi, I have date and returns for 5 factors in different columns. I need to construct a equally weigh…
Delete TestTitle …
Understanding and interpretation of second step results of the first stage 2SRI in the two step estimation.Dear Statalisters, I am implementing a 2SRI IV estimation following Terza (2017) (see here https://…
Difference in difference in survey dataDear Statalists, Is there away to do a difference in difference using survey data? Regards, Christ…
Subscribe to:
Post Comments (Atom)
0 Response to Efficient way to calculate maximum number of observations before and after a specific value in a column
Post a Comment