Stata loops for two lists of variables

Viewed 24

I am looking for a way to run a for loop for a variable list, based on the value in a corresponding list, where it takes a specific value.

The enrollment variables are numeric and represent counts of people enrolled and the second list is the program in each year that is categorical and represents if the enrollment is in program 1 or program 2. Is it possible to run summary statistics of the enrollment figures based on program = program 1?

Each of the variables has the same prefix enrollment_ or program_ and a different suffix based on the program year 1 (yr1), year 2 (yr2), or year 3 (yr3) for example,

Possible to use a do loop where the second list takes a specific value in that year?

local vars enrollment_yr1 enrollment_yr2 enrollment_yr3 

program_yr1 program_yr2 program_yr3 where programyr == "program_1"

foreach var of local vars {
    sum `var', detail if program_yr == "program 1"
}
0 Answers
Related