Hi, I am having trouble using levelsof in a loop within a loop. Each row of the data has a "country" and "region" variable. For instance,
I am trying to create a graph based on the logistic regression for every country, and combine the graphs by region. I hope to use a double-loop to accomplish this but now am stuck and cannot find what's wrong with the codes.
region is coded numerically range from 1-7 for 7 world regions.
country is coded as string.
and it returns nothing. I ran single loops for "region" and "country" and both works, but when combined they don't.
My next step would be to add marginsplot and combine all the graphs of the countries in the same region, producing 7 graphs covering all regions. See below.
Any help would be appreciated!
ID | region | country | wave | highested | participation |
1 | Latin America | Mexico | 1981-1984 | 1 | 1 |
2 | North American & Western Europe | United States | 1981-1984 | 2 | 0 |
region is coded numerically range from 1-7 for 7 world regions.
country is coded as string.
Code:
levelsof region, local(region_l) // foreach y of local region_l { levelsof country if region_l== `y', local(country_l) foreach v of local country_l { logit participation i.highested if region==`y' & country=="`v'" } }
My next step would be to add marginsplot and combine all the graphs of the countries in the same region, producing 7 graphs covering all regions. See below.
Code:
levelsof region, local(region_l) // foreach y of local region_l { levelsof country if region_l== `y', local(country_l) foreach v of local country_l { logit participation i.highested if region==`y' & country=="`v'" margins highested marginsplot, /// saving(`v', replace) } graph combine `v', title("`y'") }
Comment