Hi, I have written code to iteratively use a list of dta files. Now I want to generate a var which is named according to the first character of the dta file.
Here is my current code, where the var is named according to the entire file name:
I want to generate a var in each file, e.g. afile.dta would contain the var: a_var
I have tried adding a line before the gen line to generate a local which displays the first letter of the element, but I'm not sure what command to use to do so as substr is not allowed (see below). Perhaps a command like word but for single characters?
I'd be very grateful if somebody could advise on the command!
Many thanks,
Liz
Here is my current code, where the var is named according to the entire file name:
Code:
foreach file in afile bfile cfile { gen `file' = x_var }
I have tried adding a line before the gen line to generate a local which displays the first letter of the element, but I'm not sure what command to use to do so as substr is not allowed (see below). Perhaps a command like word but for single characters?
Code:
foreach file in afile bfile cfile { local shorthand di : substr("`fluid'", 1, 1) gen `file' = `shorthand'_var } substr not allowed
Many thanks,
Liz
Comment