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: How to make local condition for graph command


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to make local condition for graph command
Date   Sun, 9 Dec 2012 02:13:58 +0000

Alternatively, move your statement

local p25

just inside the loop and after -stci- put

if r(p25) < . local p25 = round(r(p25))


On Sat, Dec 8, 2012 at 11:50 PM, Caleb Southworth
<caleb.southworth@gmail.com> wrote:
> This code creates a table and Kaplan Meier graphs for five
> event-history outcomes.
>
> My problem is that under some circumstances, the 25th percentile is
> undefined, so my -local p25- is undefined. This causes graph to crash
> because I cannot specify a line at a missing value. Could someone
> propose a work-around that is the logical equivalent of
>
> local p25="" if missing(r(p25))
>
> The crash occurs in the line "sts graph" when missing(r(p25))
>
> begin code:
>
> set more off
> log using ${docpath}stdesc.txt, text replace
> log off
> local mean
> local p25
> assert event!=.&event<=5
> forval i=1/5 {
>         qui stset app_dt, fail(event==`i') id(Cin) origin(time td(1Jan2008)) noshow
>         qui log on
>         qui stdescribe
>         di "event= " `i' " subjects= " r(N_sub) " failure= " r(N_fail) "
> mean= " r(f_mean)
>         qui log off
>         qui stci, rmean
>         local mean=round(r(rmean))
>         qui stci, p(25)
>         local p25=round(r(p25))
>         sts graph, xline(`p25' `mean') xlab(0(300)1500 `p25' `mean',
> angle(45)) saving(${gphpath}km`i'.gph, replace)
>         }
> log close
>
> Here's the actual crash:
>
> event= 4 subjects= 63399 failure= 696 mean= .01097809
> invalid label specifier, :  . 1537:
> r(198);
*
*   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