Hi all,
I am new to STATA, and I am trying to pick up new coding to improve my efficiency. The subject line says it all for what I am trying to accomplish.
The example: I have a variable that is a classification system "ota_classification" for which there are 9 coded values (1,2,3...9). What I would like to do is generate a local variable (without actually keeping the variable) for each of the values so that I can run a chi-square against each different value for the classification system.
I can do this the long way ie.
gen ota_classification1 = ota_classification =1
tab ota_classification1 outcome, chi row
gen ota_classification2 = ota_classification =2
tab ota_classification2 outcome, chi row
etc etc
Can I do this with the foreach or forvalues command along with "local" so that I am not truly generating a new variable every time?
Thanks in advance for the help.
I am new to STATA, and I am trying to pick up new coding to improve my efficiency. The subject line says it all for what I am trying to accomplish.
The example: I have a variable that is a classification system "ota_classification" for which there are 9 coded values (1,2,3...9). What I would like to do is generate a local variable (without actually keeping the variable) for each of the values so that I can run a chi-square against each different value for the classification system.
I can do this the long way ie.
gen ota_classification1 = ota_classification =1
tab ota_classification1 outcome, chi row
gen ota_classification2 = ota_classification =2
tab ota_classification2 outcome, chi row
etc etc
Can I do this with the foreach or forvalues command along with "local" so that I am not truly generating a new variable every time?
Thanks in advance for the help.
Comment