Bookmark and Share

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


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

Re: st: Looping graphs and changing graphs name


From   [email protected] (Vince Wiggins, StataCorp)
To   [email protected]
Subject   Re: st: Looping graphs and changing graphs name
Date   Mon, 03 Dec 2012 20:31:02 -0600

Evelyne Fournier <[email protected]> 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 
   [email protected]

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index