Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Looping graphs and changing graphs name

From   Evelyne Fournier <>
To   <>
Subject   st: Looping graphs and changing graphs name
Date   Mon, 3 Dec 2012 15:59:33 +0100

Dear all,

I'm having a problem using levelsof.
I know this subject has been widely discussed in previous posts. Unfortunately my loop over values of a string variable doesn't want to work and I can't figure out why.

I have a dataset containing incidence et mortality rates by age categories (clage). I have a string variable containing cancer localisations (loc). I want to graph incidence and mortality rates per age category and produce one graph per cancer localisation. I want the created graphs to have the name of the given cancer localisation.

My dataset looks the following
          loc     clage     incid     morta
   Système Nerveux  50-54   23.96       5.99
   Système Nerveux  55-59   30.11     10.03
   Système Nerveux  60-64   58.73      22.58
   Système Nerveux  65-69   49.92      16.64
   Système Nerveux  70-74   58.20       47.28
   Système Nerveux  75-79   121.10      60.55
   Système Nerveux  80-84   90.43     71.05
   Système Nerveux  85and +    103.26     150.20

When I execute the following code, Stata doesn't go over the different localisations. However, the loop works as long as I don't try to save the graph with the cancer localisation's name (command line name("`lev'", replace) here under).
levelsof loc
foreach lev in `r(levels)' {
           keep if loc=="`lev'"
   twoway (line incid clage, sort) ///
  (line morta clage, sort )  ///
 title("`lev'")  ///
name("`lev'", replace)
I get the following message :
Système Nerveux : (line incid clage, sort) (line morta clage, sort), title("Système Nerveux Central"): class type not

Any help will be greatly appreciated.


Evelyne Fournier
Registre des tumeurs du Doubs et du Territoire de Belfort
CHU Besancon,
2 Place Saint Jacques
25030 Besancon Cedex

fn:Evelyne Fournier
org:CHU Besancon;Registre des tumeurs du Doubs
adr:;;2 Place Saint Jacques;Besancon;;25000;France
tel;quoted-printable;work:18314 (depuis l'int=C3=A9rieur) ou 03 81 21 83 14

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index