Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Plot after regression using linear splines - any way to add confidence intervals?


From   Nils Braakmann <nilsbraakmann@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Plot after regression using linear splines - any way to add confidence intervals?
Date   Fri, 17 Jul 2009 08:51:14 +0200

Now, this helps a lot!

Thanks and a nice weekend,
Nils

On Fri, Jul 17, 2009 at 8:33 AM, Maarten buis<maartenbuis@yahoo.co.uk> wrote:
>
> --- On Thu, 16/7/09, Nils Braakmann wrote:
>> thanks. However, I would like the plotted interval to
>> reflect the precision of the underlying parameter
>> estimates.
>
> OK, that can make sense too: the coefficients are in this
> case the marginal effects, i.e. the first derivative of
> the curve I gave in the previous post.
>
> *-------------------- begin example -------------------
> use http://www.stata-press.com/data/r10/nlswork, clear
> xtset idcode year
> mkspline agespl 20 = age, dis
> matrix knots = r(knots)
> sum age, meanonly
> local min = r(min)
> local max = r(max)
>
> xtreg ln_wage agespl*, fe cluster(idcode)
>
> preserve
> drop _all
> set obs 21
> gen x = `min' in 1
> gen b = _b[agespl1] in 1
> gen se = _se[agespl1] in 1
>
> forvalues i = 2/20 {
>        replace x = el(knots,1,`=`i'-1') in `i'
>        replace b = _b[agespl`i'] in `i'
>        replace se = _se[agespl`i'] in `i'
> }
> replace x = `max' in 21
> replace se = _se[agespl20] in 21
>
> expand 2
> sort x
> by x : gen first = _n == 1
> replace b = b[_n-1] if first
> replace se = se[_n-1] if first
>
> gen lb = b - 1.96*se
> gen ub = b + 1.96*se
>
> twoway rarea lb ub x || ///
>       line b x, yline(0)
> restore
> *-------------- end example ------------------
>
> Hope this helps,
> Maarten
>
> -----------------------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://home.fsw.vu.nl/m.buis/
> -----------------------------------------
>
>
>
>
> *
> *   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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index