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
Replacing a data variable if data falls within a date rangeI have some data that was misclassified for a certain date range and would like to change using Stat…
logistic regression.Hae guys have been trying to figure out the command for testing linearity assumption for log odds vs…
Delete-one-node jackknife variance estimatorDear colleagues, using a dataset on bilateral trade (i.e. country g exports to h leading to the nod…
ivreg2h: generated instrumentsDear All, I am using the ivreg2h user-written routine, which implements the procedure in Lewbel (20…
dependent variable "a percentage" and independent variables are in millions !hi, i have panel data "micro panel" i used "gmm method" without unifying variables, the dependent…
Subscribe to:
Post Comments (Atom)
0 Response to Expand sample using levels of a variable
Post a Comment