I am a grad student with experience in R, currently working on Stata for a RAship. Hence I am a beginner on this plateform but eager to learn.
I have encountered a problem with my own dataset, that the following example illustrates well.
Suppose I want to convert variables in inches to centimeters in the auto dataset. I could do this which gets me the result I want.
Code:
sysuse auto, clear foreach var of varlist headroom length{ gen `var'_cm = `var'*2.54 }
A local macro seems appropriate to solve for that and make the code more self-documented.
I have tried the following code, which can be executed without Stata throwing an error, yet without coming near the expected result.
Code:
sysuse auto, clear local vars_inch headroom length foreach var of local vars_inch { gen `var'_cm = `var'*2.54 }
This is eventually a basic syntax issue, I would be very thankful if someone could point me out to the correct syntax.
Best,
Axel
0 Response to looping over variables in a local macro
Post a Comment