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