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: Force x-axis range to be the bounds of the variable in the sample, not the entire data set


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Force x-axis range to be the bounds of the variable in the sample, not the entire data set
Date   Mon, 27 Aug 2012 18:24:41 +0100

The x axis range you get is unrestricted because your -rarea- call is unrestricted. Try adding an -if- qualifier to that too.

Nick

On 27 Aug 2012, at 17:05, Aaron Kirkman <[email protected]> wrote:

I'm calculating and generating prediction intervals for a subset of a
data set, but when I graph the subset, the range on the x-axis is the
range of all of the data, instead of only the sample. For example:

###

use "http://www.stata-press.com/data/imeus/hprice2a";, clear
sort lnox

summ lnox
summ lnox if _n <= 100

###

. summ lnox

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       lnox |       506    1.693091    .2014102   1.348073   2.164472

. summ lnox if _n <= 100

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       lnox |       100    1.435845    .0361544   1.348073    1.48614

The range of the sample is [1.348073, .48614], but when I calculate
and graph the predicted values, the range of -lnox- is [1.348073,
2.164472], which is too large. Here is the complete do-file:

###

use "http://www.stata-press.com/data/imeus/hprice2a";, clear
sort lnox

summ lnox
summ lnox if _n <= 100

quietly regress lprice lnox if _n <= 100
predict double xb if e(sample)
predict double stdpred if e(sample), stdp
scalar tval = invttail(e(df_r), 0.975)
gen double uplim = xb + tval * stdpred
gen double lowlim = xb - tval * stdpred

summ lnox if e(sample), meanonly
local lnoxbar = r(mean)
label var xb "Predicted"
label var uplim "95% prediction interval"
label var lowlim "95% prediction interval"

#delimit ;

twoway
(rarea lowlim uplim lnox, sort bcolor(gs14))
(scatter lprice lnox if e(sample), sort ms(Oh) xline(`lnoxbar'))
(rline uplim lowlim lnox if e(sample), sort),
       ytitle("Actual and predicted log price") legend(cols(1))
       xsize(18) ysize(12);

#delimit cr

###

Is there a way to automatically do this, or should I manually specify
-xaxis- and -xlabel- ?


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


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