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
Friedrich Huebler <[email protected]>
To
[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 12:58:04 -0400
Aaron,
You can automate the range and labels of the x-axis. For example, if
you want the x-axis to have a range of 1.3 to 1.5, with labels at
steps of 0.1, you can do the following.
. sum lnox if _n <= 100
. local xmin = floor(r(min)*10)/10
. local xmax = ceil(r(max)*10)/10
. scatter lprice lnox, xscale(r(`xmin' `xmax')) xlabel(`xmin'(.1)`xmax')
Friedrich
On Mon, Aug 27, 2012 at 12:05 PM, 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- ?
>
> 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/