I have been trying to use ‘numlist’ in a foreach loop as I have a list of about 100 variables, all repeated 8 times (as if in a longitudinal study) and the only difference in each variable name is the numbers 1 to 8.
Example variables:
v1_msg v2_msg v3_msg v4_msg v5_msg v6_msg v7_msg v8_msg
v1_age v2_age v3_age v4_age v5_age v6_age v7_age v8_age
And I’m using the code:
foreach num in numlist 1 2:8 {
tab v`num'_msg, m
tab v`num'_age, m
}
I got the error r(111) "variable vnumlist_msg not found"
I then added a display command first to see if my loop was even working:
foreach num in numlist 1 2:8 {
di `num'
tab v`num'_msg, m
tab v`num'_age, m
}
And I got the error r(111) "numlist not found"
My question is, is this possible with this command? And if not - how can I achieve this outcome without repeatedly typing each variable name 8 times. I also want to do more then just tabulate each variable in foreach.
I have also tried using variable wild cards such as:
tab v*_msg
tab v#_msg
These also gives me the errors: r(103) "too many variables specified" and then r(111) "v ambiguous abbreviation" (respectively).
Thank you for your help!
Victoria
Related Posts with Numlist in foreach loop, when number is within variable name
What is wrong with my bootstrap program, and why does it give the same estimates in every bootstrap sample?Lets say that I am trying to compare -reg3- estimates over two different subsamples, using bootstrap…
Gmm Estimator in panel data simultaneous EquationHello In Stata software version 15 , if I want to check and see the result of individuals in GMM Est…
xtlogit vce(cluster cvar) returning no standard errorsHello everyone, I have a panel dataset. The dependent variable is information on whether an investm…
Bootstrapped Maximum likelihood estimationDear Statalist users, I am trying to write a code in order to estimate a linear regression with boo…
Gmm Estimator in panel data simultaneous EquationIn Stata software version 15 , if I want to check and see the result of individuals in GMM Estimator…
Subscribe to:
Post Comments (Atom)
0 Response to Numlist in foreach loop, when number is within variable name
Post a Comment