I have a large dataset with rows that include a unique identifier 'id' and a unique time variable called 'timeto'. There are variable numbers of duplicate id's but all in the dataset are duplicated at one point or another. I would like to create a flag indicating when two rows with the same id have 'timeto' values that are <= 2. If there are more than one, I'd like to count up. Examples below:
starting data:
id timeto
1 3
2 7
2 8
2 0
2 14
2 15
3 4
3 6
ending data:
id timeto flag
1 3 0
2 7 1
2 8 1
2 0 0
2 14 2
2 15 2
3 4 1
3 6 1
Eventually, for those 'pairs' of rows with the same ID and timeto within 2, I'd be planning to pivot wide so there is a single row for each ID. Any help would be appreciated!
Related Posts with Identifying and flagging matches
Endogeneity in panel dataDear all, as far as I know, endogeneity exists when the independent variable is correlated with the…
Wald exogeneity test with -ivprobit- interpretation and exporting resultsDear Statalisters I am running an -ivprobit- regression and have got a p-value for the Wald exogene…
catplot - how to control the gap between bars when 3 variables are usedThis post is about the package catplot, contributed by Nick Cox. The help file shows an example illu…
Summing z scores in a new combined standardized variable stataI have data with anthropometics (e.g. weight, height, waist cercumference...) and blood samples (e.g…
Dealing with missing values in 2SLS regression - in instrumental variablesHi I am about to make a 2SLS regression. This is a corrected IV model where I have som instrumental…
Subscribe to:
Post Comments (Atom)
0 Response to Identifying and flagging matches
Post a Comment