I am trying to generate a wave variable in a panel dataset using substring (as I had seen used elsewhere). A wave prefix letter is attached to the beginning of each variable denoting the wave, e.g. 'a' as in asex = wave 1, 'b' as in bsex = wave 2, etc hence the string "a, b, c, ...". I read a number of previous posts but I was not able to find a solution or to know whether this function is the right one for the code I'm trying to write. Help is appreciated.
Code:
local wave = substr(c(alpha), 1, 17) // I tried this without success
//local waveprefix = substr("abcdefghijklmnopq","a" , 17) // I tried this without success also
foreach waveprefix in `wave'{
quietly{
use `origdatadir'/Combined_`waveprefix'170c.dta, clear
}
keep `list'
gen wave = index("abcdefghijklmnopqrstuvwxyz","`waveprefix'")
lab var wave "Wave of the survey"
sort hhpxid
save "`mergedata'", replace
}
0 Response to Difficulty using substring function
Post a Comment