I'm trying to use a loop to do several tabulations all at once. I'm using survey data, and have two distinct categories of variables: Q52* and Q53* where each '*' is a letter from the alphabet A-R. I know I could change the variable names to numeric and run a loop that way, but I was looking to see if there was an easy way to loop through letters; my searches haven't yielded anything I can use. I need to match the two groups to each other based on the alpha - for instance, Q52A to only Q53A. I can do them one at a time using
svy linearized : tabulate Q52G Q53G, count cell
but I want something similar to:
quietly forval j = A/R {
forval k = A/R {
svy linearized : tab Q52`i' Q53`j' if (Q52`j'==Q53`k'), count cell
}
}
Obviously, this does not work with letters, but is there a way to do this or should I just do them one at a time?
svy linearized : tabulate Q52G Q53G, count cell
but I want something similar to:
quietly forval j = A/R {
forval k = A/R {
svy linearized : tab Q52`i' Q53`j' if (Q52`j'==Q53`k'), count cell
}
}
Obviously, this does not work with letters, but is there a way to do this or should I just do them one at a time?
Comment