Using Stata 15.1/Win 10
I am trying to replace missing values in variable "drop" below equal to 1 if any observations by group are missing for drop and one of the values in drop by group is 0. The way that the dataset is constructed is such that there will be only one value of 0 for each group (i.e. keeping one and only one observation by group). I'd like drop to take a value of 0 when all remaining within group values of drop are not missing and each equals 1.
The variable descriptions:
group: by group identifer
pid_ord: within group rank
count: within group N
latest: 1 when pid_ord == N by group, 0 otherwise
drop: 1 tags for drop, 0 tags for keep. These values were generated based on other arguments, but I am only interested in populating the missing values that meet the conditions above.
For example, no observation in group 1 would be replaced (no missing); the missing observation in group 2 would be 0 becuase there is only one observation left that is not 1; group 4 missings would be replaced with 1 since an observation for drop is 0, and so on. Thanks in advance for your help!
I am trying to replace missing values in variable "drop" below equal to 1 if any observations by group are missing for drop and one of the values in drop by group is 0. The way that the dataset is constructed is such that there will be only one value of 0 for each group (i.e. keeping one and only one observation by group). I'd like drop to take a value of 0 when all remaining within group values of drop are not missing and each equals 1.
The variable descriptions:
group: by group identifer
pid_ord: within group rank
count: within group N
latest: 1 when pid_ord == N by group, 0 otherwise
drop: 1 tags for drop, 0 tags for keep. These values were generated based on other arguments, but I am only interested in populating the missing values that meet the conditions above.
For example, no observation in group 1 would be replaced (no missing); the missing observation in group 2 would be 0 becuase there is only one observation left that is not 1; group 4 missings would be replaced with 1 since an observation for drop is 0, and so on. Thanks in advance for your help!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(group pid_ord count latest drop) 1 1 2 0 1 1 2 2 1 0 2 1 2 0 1 2 2 2 1 . 3 1 2 0 1 3 2 2 1 0 4 1 6 0 1 4 2 6 0 . 4 3 6 0 . 4 4 6 0 . 4 5 6 0 . 4 6 6 1 0 5 1 3 0 1 5 2 3 0 . 5 3 3 1 0 6 1 3 0 1 6 2 3 0 . 6 3 3 1 0 7 1 2 0 1 7 2 2 1 0 end
Comment