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
option lc() not allowed \ option lcolor() not allowedDear all, Even though I found similar posts online, I still could not manage to fix this. The code …
Help! Unexpected impact of controlling an omitted variableHi everyone, I'm estimating production function using firm-level panel data (6 years) to obtain fir…
Xtabond postestimation - export results to ExcelDear all, I estimate a dynamic panel model using xtabond command. Next I use xtabond postestimation…
Problem with a dummyHi. I have to create a dummy variable which is zero if a variable "x1"=0 and it is egual to 1 if x2,…
generating variable with logical operatorsDear Statlisters I have data on ownership of household assets. I want to generate variables where l…
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