automatic graphs

Viewed 31

I have a database in Stata by country and the regions these belong to. I want to create graphs with one variable (varA) by year for each region. In each graph I want the line of varA of every country belonging to that region.

I want to do it automatically because there are a lot of countries (however only five regions). Any help to do this?

The database is like this: region varA country 1 year 1 1 country 1 year 2 1 country 2 year 1 2 country 2 year 2 2 country 3 year 1 2 country 3 year 2 3

I tried using foreach command to loop the creation of the graphs but I can not figure out how to put in each region graph all the varA line series of each country in the region.

1 Answers

You don't show your code but I don't see that you need a loop here. The essence of what you want may be a line graph using by() to specify different regions.

This is an example you can run in your Stata. Some of the details won't necessarily apply to your dataset. company corresponds to country and group to region and invest to varA.

webuse grunfeld, clear 
gen group = mod(company, 2)  
xtset company year 
line invest year, c(L) by(group, imargin(medsmall) note("")) ysc(log) yla(1 10 100 1000, ang(h)) xtitle("")
Related