I am working with panel data for two waves at the moment. The dependent variable (outcome) is a binary variable (0 / 1). There are multiple observations of the outcome variable for every ID and wave.
I have imputed the missing values for the outcome variable by using:
mi impute logit outcome (predictor variables), augment force add(20)
ID | wave | outcome
1 | 1 | .
1 | 1 | 1
1 | 1 | .
1 | 2 | .
1 | 2 | 1
1 | 2 | 0
Up to this point, everything worked well. However, with regard to my research question, I am interested in whether at least one observation for the outcome variable is ==1 for every ID and wave. In other words, I want to generate a new variable based on the imputed variable that identifies whether one observation per ID and wave has a value of 1. Therefore, I generated two new variables: total_`num'_outcome which sums up the values of the outcome variable by ID and wave. _`num'_outcome_g1 is a binary variable (0 / 1) that identifies whether total_`num'_outcome is 0 or >1. The latter identifies whether at least one observation of the outcome variable for every ID and wave is 1.
foreach num of numlist 1/20 {
bysort ID wave: egen total_`num'_outcome = total(_`num'_outcome)
by ID wave: gen _`num'_outcome_g1 = 1 if total_`num'_outcome>0 & total_`num'_outcome!=.
replace _`num'_outcome_g1=0 if total_`num'_outcome==0
}
This results in:
ID | wave | outcome | _mi_miss | _`num'_outcome | total_`num'_outcome | _`num'_outcome_g1 | and so on
1 | 1 | . | 1 | 1 | 2 | 1 |
1 | 1 | 1 | 0 | 1 | 2 | 1 |
1 | 1 | . | 1 | 0 | 2 | 1 |
1 | 2 | . | 1 | 1 | 2 | 1 |
1 | 2 | 1 | 0 | 1 | 2 | 1 |
1 | 2 | 0 | 0 | 0 | 2 | 1 |
For the next step, I want to keep only one observation for every ID and wave regarding the outcome variable. To estimate my models, I want stata to use the aggregated variables _`num'_outcome_g1 instead of the imputed values in _`num'_outcome.
My questions:
(1) Is such an appraoch possible in stata?
(2) How do I run the estimation command on the _`num'_outcome_g1 variables instead of the "original" imputed data in _`num'_outcome?
Best regards
Fabian
Related Posts with panel data: aggregate imputed variables to a new variable using mi
Format the number of decimals in Table command in Stata-17Hello everyone. I use the command below to determine the number of decimals in my table in Stata-17.…
Sample from joint distributionHi, I was wondering if there is a way to generate a dataset with 100 observations, with two variabl…
Event study using "never treated" units - DID multiple periodsHello everyone, I am applying DID with multiple periods using csdid and "never treated" units as co…
How to generate mean by groupGood morning everyone ! I have a problem of calculating the decile by group. Here is the datset that…
Stochastic Frontier Approach (SFA): Why the sfpanel results are different by z variable order?Dear all, I'm on the research, based on stochastic frontier approach (SFA), Battese and Coelli time-…
Subscribe to:
Post Comments (Atom)
0 Response to panel data: aggregate imputed variables to a new variable using mi
Post a Comment