Dear Statalisters,
I have, for example, two variables a1 and a2 of which the labels are:
I would like to extract parts of the label which is any number followed by two words and store the extracted portion in a local macro. My code works if I generate a new variable:
But does not work if I want to store the partial label in a local macro:
Any idea how to store them in a macro. I have several other variables which needs to feed in a program with the extractions.
Thank you.
I have, for example, two variables a1 and a2 of which the labels are:
Code:
des a1 a2 Variable Storage Display Value name type format label Variable label ------------------------------------------------------------------------------------------------------------------------------------------------- a1 byte %8.2f Maternal anxiety at 18 weeks gestation [original label B_CCEI_AnxietySubscale] a2 byte %8.2f Maternal anxiety at 32 weeks gestation [original label C_CCEI_AnxietySubscale]
Code:
foreach v of varlist a1 a2 { loc t : var lab `v' g `v'l = ustrregexs(0) if ustrregexm("`t'", "[0-9]+[\s]+[\w]+[\s]+[\w]+") } li a1l a2l in 1/3 +-----------------------------------------+ | a1l a2l | |-----------------------------------------| 1. | 18 weeks gestation 32 weeks gestation | 2. | 18 weeks gestation 32 weeks gestation | 3. | 18 weeks gestation 32 weeks gestation | +-----------------------------------------+
But does not work if I want to store the partial label in a local macro:
Code:
foreach v of varlist a1 a2 {
loc t : var lab `v'
loc k : ustrregexs(0) if ustrregexm("`t'", "[0-9]+[\s]+[\w]+[\s]+[\w]+")
}
ustrregexs not allowed
Thank you.
Comment