Suppose I have four variables: age, income, race, and county. I want to summarize age and income, and tabulate race and county. Obviously there are easier ways to do this, but in the context of the problem I'm trying to solve, I need to create a list of variable names, and summarize one list, and tabulate the other list, all within a loop that runs through all variables. Here is the idea:
I've tried using "if" as both a qualifier and a command (still a little shaky on which to use in certain contexts), and I have been trying to use the inlist() command, but I'm still not getting what I want, so I must either be using it wrong or I'm barking up the wrong tree. I think my problem is just a matter of some random syntax I was never taught and can't find online, but nonetheless I'm stuck.
HTML Code:
foreach var in age income race county { loc sumvars age income loc tabvars race county */ sum `var' if `var' is contained in sumvars /* */ tab `var' if `var' is contained in tabvars /* }
Comment