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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

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 |

Nick On 27 Aug 2012, at 17:05, Aaron Kirkman <ak5791@gmail.com> 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/

**References**:**st: Force x-axis range to be the bounds of the variable in the sample, not the entire data set***From:*Aaron Kirkman <ak5791@gmail.com>

- Prev by Date:
**Re: st: standard normal distribution** - Next by Date:
**Re: st: Esimates Table commend** - Previous by thread:
**Re: st: Force x-axis range to be the bounds of the variable in the sample, not the entire data set** - Next by thread:
**st: Esimates Table commend** - Index(es):