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
Shapley value decomposition (regression-based decomposition)I want to use the Shapley value decomposition approach to estimate the contribution of a set of fact…
Change values without changing labelsHi, I have the following dataex for what I have a question about: Code: clear input int(H2PF1 H2PF…
Condense household observationsHi all, Apologies in advance, I'm an inexperienced undergrad. I have a dataset which has 1 househo…
Vertical axis label not showing after converting to pdfI have created a marginplot graph after running a logit regression. After editing the graph in stat…
Group-year FEs do not absorb the group-level treatmentHi Statalist, I'm running a DiD with a continuous treatment at the group (industry) level. The trea…
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