Hi everyone! I am having some trouble creating new variables. My goal is for the name of the variable to be looped. To be precise, I want to create as many variables as the max value of another variable called cal_year_duration, and then the name of the new variable should be Y1 if year_duration =1, Y2 if year_duration=2. My code to this point looks like this and there is a sample of data below, but I'm pretty sure I am doing something wrong so any help would be greatly appreciated. Thanks in advance!
forvalues i=1 & i<=max(cal_year_duration) {
gen Y`i'= .
}
. dataex cal_year_duration
forvalues i=1 & i<=max(cal_year_duration) {
gen Y`i'= .
}
. dataex cal_year_duration
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float cal_year_duration 1 2 5 15 3 4 2 7 8 1 end
Comment