Hello statalist,
I am using Stata 15.1. I would like to expand a sample using the levelsof one variable. The objective is that for my ID unit (country) I record whether a measure has been taken or not.
Here the data:
input str3 iso3 str22 Country long level1
"AFG" "Afghanistan" 1
"AFG" "Afghanistan" 1
"AFG" "Afghanistan" 1
"AFG" "Afghanistan" 1
"AFG" "Afghanistan" 1
"AFG" "Afghanistan" 3
"AGO" "Angola" 3
"ALB" "Albania" 1
"ALB" "Albania" 1
"ALB" "Albania" 1
"ALB" "Albania" 3
"ALB" "Albania" 3
Basically, I have a list of countries. I have a variable that records for each country a "level1" measure taken. "level 1" can take up to 5 values. Level 1 measures can be repeated (as seen above, AFG has 5 observations taking value of 1 for the "level 1").
I would like to add observations to the data set so each country can have a maximum of 5 level 1 measures. For countries that do not report a specific measure (e.g., Afghanistan in the example below not recording level1=2, level1=4, level1=5), I would like just to add one line for each missing measure. Then createa new variable ("Level1_taken_fictious") that takes value of 1 if a specific "level1" measure has been taken, 0 otherwise. Below I report an example just for AFG to exemplify the new data set I would like to create.
iinput str3 iso3 str22 Country long level1 float Level1_taken_fictious
"AFG" "Afghanistan" 1 1
"AFG" "Afghanistan" 1 1
"AFG" "Afghanistan" 1 1
"AFG" "Afghanistan" 1 1
"AFG" "Afghanistan" 1 1
"AFG" "Afghanistan" 2 0
"AFG" "Afghanistan" 3 1
"AFG" "Afghanistan" 4 0
"AFG" "Afghanistan" 5 0
I hope you can help me.
Davide
Related Posts with Expand sample using levels of a variable
Changing x-axis from days into years on kaplan meierDear Stata community, Thank you for all your help so far. I am doing some KM analysis for my study…
Wald Test with binary predictor - does this make sense?Hi there, to evaluate my logistic regression model I am planing to perform a wald test. Besides my …
Deseasonalize dataHi all, Hope everything's fine on your side! I have a dataset having as inputs: the id of products,…
Moderation analysis - Interaction Term is significant, but the marginal effects are not.Hello, just in case my question is trivial, I am a novice at econometric and Stata. I did my resear…
graph combine / grc1leg question: How to get one axis title for alle subgraphs?Hello everybody, I have a queation about graph combine, or in my specific case grc1leg, but since t…
Subscribe to:
Post Comments (Atom)
0 Response to Expand sample using levels of a variable
Post a Comment