Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Looping graphs and changing graphs name


From   vwiggins@stata.com (Vince Wiggins, StataCorp)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Looping graphs and changing graphs name
Date   Mon, 03 Dec 2012 20:31:02 -0600

Evelyne Fournier <efournier@chu-besancon.fr> is having a problem naming
graphs in a loop. Here is an excerpt of Evelyne's data,

           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

And, here is a simplification of the code, 

	levelsof loc
	foreach lev in `r(levels)' {
		preserve
		keep if loc=="`lev'"
		twoway line incid clage, name("`lev'", replace)
		restore
	}

To which, Stata replies,

Système Nerveux : .twowaygraph_g.new (line incid clage, sort) (line 
morta clage, sort), title("Système Nerveux Central"): class type not
     found
r(4018);

This is an unfortunate and unhelpful error message that we will improve
in a future update.

The source of the problem, however, is the contents of Evelyne's loc
variable.  That variable includes spaces and extended ASCII characters,
neither of which are allowed in Stata names.  See [U] 11.3 Naming
conventions.

One possible solution is to simply number the graphs with a leading
stub.  For example,


	local i 0
	levelsof loc
	foreach lev in `r(levels)' {
		preserve
		keep if loc=="`lev'"
		twoway line incid clage, name(stub`++i', replace)
		restore
	}

 
-- Vince 
   vwiggins@stata.com

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index