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]
st: Force x-axis range to be the bounds of the variable in the sample, not the entire data set
From 
 
Aaron Kirkman <[email protected]> 
To 
 
[email protected] 
Subject 
 
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 11:05:28 -0500 
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- ?
Thank you,
Aaron
*
*   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/