Hi there, I have 2 dta files (csf_final.dta; plasma_final.dta) which I am using iteratively via a loop. In each file, I want to generate a var which is named based on the file name, according to my loop. I then want to label the var based on the file name, but changing the case depending on the file.
In csf_final.dta, I want the label to read: "CSF concentration (pg/mL)"
In plasma_final.dta, I want the label to read: "Plasma concentration (pg/mL)"
I know I can change the dta file names and list elements to the desired cases, but I was wondering if I could fix this by code instead.
I thought I could use the following locals (in blue):
I was hoping somebody might help advise on how best to then indicate the corresponding local to use in the label line (I would want csf to use ``fluid'_upper' and plasma to use ``fluid'_proper')?
I'd be very grateful for some help!
Many thanks,
Liz
Code:
foreach fluid in csf plasma { use `fluid', clear gen `fluid'_var label variable `fluid' "`fluid' concentration (pg/mL)" }
In plasma_final.dta, I want the label to read: "Plasma concentration (pg/mL)"
I know I can change the dta file names and list elements to the desired cases, but I was wondering if I could fix this by code instead.
I thought I could use the following locals (in blue):
Code:
foreach fluid in csf plasma {
use `fluid', clear
local `fluid'_upper : di "upper(`fluid')"
local `fluid'_proper : di "proper(`fluid')"
gen `fluid'_var
label variable `fluid' "`fluid' concentration (pg/mL)"
}
I'd be very grateful for some help!
Many thanks,
Liz
Comment