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
Omitted variableI am working with panel data and xtreg with fixed effects. 3 of my variables result in Omitted after…
How to ignore non converging GARCH(1,1)Dear all, I am currently in the process of trying to replicate a paper by O'Brien & Folta: "Sun…
Logistic regression with an interaction term of two predictor variables? Do we can interpret non-significant coefficient?Hello, I am a bit curious about the interpretation of results given from: https://stats.idre.ucla.e…
mhodds Test of homogeneity of ORs Pr>chi2Hello Statalist! I am having trouble retrieving the Pr>chi2 for a Test of homogeneity of ORs usi…
Xtmelogit - very long calculation time, any solution?Dear all, I am new to multilevel modeling and I am struggling with it on Stata. Specifically, I am…
Subscribe to:
Post Comments (Atom)
0 Response to Expand sample using levels of a variable
Post a Comment