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
Specific period Buy and Hold returns for every dayHello everyone, I have daily panel data with prices and returns for several companies. My question …
regression coefficient calculation not correctHello everyone, My coefficient for my Construction costs index is too high I have correct construct…
Getting regression results for my last dummyHello everyone, I have 3 dummy variables where I have created 2 variables one is called low_dev and…
Latitude and Longitude to perform geonear and the case of 90 to -90To perform geo near, we require latitude and longitude. For this do we use the coordinates informati…
(ssc) esttab and stcrreg: option equations() invalidFor some reason esttab (an ssc package) will not let me combine these two outputs: Code: . stcrreg…
Subscribe to:
Post Comments (Atom)
0 Response to panel data: aggregate imputed variables to a new variable using mi
Post a Comment