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
New version of stcmd on SSCThanks as always to Kit Baum, a new version of the stcmd package is now available for download from …
Fix no room to add more variables because of width issue when splitting a long stringHi all, I have a single string that is extremely long. It has a length of about 600,000 characters …
jwdid: DID using ETwFEDear all thanks to prof. Baum a new command is ready to use. jwdid implements the did estimator prop…
Generating date variableHello all, I have the following code: Code: clear input float(qdate) 1900q1 1900q2 1900q3 1900q4 …
Error message with 'collect export' in Stata 17Hello, I have a large descriptive Table 1 that I'd like to try to export to an Excel file for a man…
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