I'm using stata 15.
I have a list of categorical variables for which I'd like to obtain info on a second variable (say, Y)- by level of categorical variable X.
For instance- I want to examine frequencies of the different level of variables such as gender, year in school (freshman, sophomore, junior, senior) etc on a second categorical variable Y e.g. 'how many interviews have you had?- 0, 1, 2, more than 2'.
Individually the code is as simple as:
Code:
bysort gender: tab interview_no bysort internationa: tab interview_no
I thought to use the foreach macro and bysort...as follows
Code:
local y code_interv local demoglist gender international edlevel bigtech /// foreach var of varlist `demoglist'{ bysort `var': tab `y' }
e.g. for gender =0, international =0 edlevel = 1 bigtech=0 etc..... Y = 0 = W%
for for gender =0, international =0 edlevel = 1 bigtech=0 etc..... Y = 1= Z % ETC
and then..
e.g. for gender =0, international =1 edlevel = 1 bigtech=0 etc..... Y = 0 = W%
for for gender =0, international =1 edlevel = 1 bigtech=0 etc..... Y = 1= Z % ETC
and on and on. Not what am looking for.
What I really want is a simplified code like the first-- i.e. just frequencies for each demographic variable separately (as in simple code #1 above); but not frequencies for Y, based on a combination of the Xs.
How do I rewrite the code (to group variables) such that I can obtain results consistent with the first simple code?
Im certain Stata has a way to accomplish this; I just dont know how. Please help.
Thanks!
0 Response to Trouble shooting for-- Foreach macro with bysort command: help!
Post a Comment