Dear Statalist,
I'd like to create a set of new variables based on the substring of two sets of variables in a loop. The manual version of what I have is
I have this process for about 20 variables, and I think there should be a way to do it in a loop since it's the same pattern. I think it could be done with the strpos()-, -substr()- or-subinstr()- options, but I am not quite sure how to do it. Below a dataex
Thank you for your help!
I'd like to create a set of new variables based on the substring of two sets of variables in a loop. The manual version of what I have is
Code:
sort state by state: gen dif_sum_temp = hi_sum_temp - lo_sum_temp by state: gen dif_wint_snowfall = hi_wint_snowfall - lo_wint_snowfall by state: gen dif_wind_force = hi_wind_force - lo_wind_force
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 state byte lo_sum_temp int hi_sum_temp byte(lo_wint_snowfall hi_wint_snowfall lo_wind_force) int hi_wind_force "CA" 80 130 20 80 0 199 "DE " 75 100 12 70 0 200 "NY" 70 115 30 100 0 231 end
Thank you for your help!
Comment