Statalist


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

st: Confidence bounds for truncated regression with cubic splines


From   Georg Pfundstein <[email protected]>
To   [email protected]
Subject   st: Confidence bounds for truncated regression with cubic splines
Date   Thu, 3 Dec 2009 11:07:05 +0100

Hello everybody,

i am totaly new to Stata and therefore need your help.
I am running a truncated regression with cubic splines, which works
quite well i think. Since i am combining two different types of
regressions i need to calculate the splines by hand which enables the
use of the predict function i think! Right? The problem is, that i
also want to calculate and plot confidence bounds for the regression
splines. Because the predict function does not work i also have to
calculate the bounds by hand and i have no clue how this works with
Stata. I am not familiar with the Stata syntax at all. Maybe anyone
can help me?

My code looks (and works) like the following:

*! --- knots ---- *!
gen K1 = 15
gen K2 = 25
gen K3 = 35
gen K4 = 45

gen tK1 = 0
replace tK1 = (t - K1)^3 if t > K1

gen tK2 = 0
replace tK2 = (t - K2)^3 if t > K2

gen tK3 = 0
replace tK3 = (t - K3)^3 if t > K3

gen tK4 = 0
replace tK4 = (t - K4)^3 if t > K4


*! ----[ estimation with ll(mhr_mix) and doryear < 1820 ] ---- *!

constraint define 1 [sigma]_cons = 2.7
truncreg height age t t_sq t_cu tK1 tK2 tK3 tK4 urban domestic transp
no_occ [pweight=1/weight] if (age >=16 & age <= 50), ll(mix) ul(75.5)
cluster(pobcode) constraint(1)

*! --- plot ---*!

matrix coef_total = e(b)
matrix b_cons=coef_total["y1", "eq1:_cons"]
scalar b_cons=el(b_cons,1,1)
matrix b_t=coef_total["y1", "eq1:t"]
scalar b_t=el(b_t,1,1)
matrix b_t_sq=coef_total["y1", "eq1:t_sq"]
scalar b_t_sq=el(b_t_sq,1,1)
matrix b_t_cu=coef_total["y1", "eq1:t_cu"]
scalar b_t_cu=el(b_t_cu,1,1)
matrix b_tK1=coef_total["y1", "eq1:tK1"]
scalar b_tK1=el(b_tK1,1,1)
matrix b_tK2=coef_total["y1", "eq1:tK2"]
scalar b_tK2=el(b_tK2,1,1)
matrix b_tK3=coef_total["y1", "eq1:tK3"]
scalar b_tK3=el(b_tK3,1,1)

twoway function y=b_cons+b_t*x+b_t_sq*x^2+b_t_cu*x^3 , range(1 15)
lcolor(black) ||  function
y=b_cons+b_t*x+b_t_sq*x^2+b_t_cu*x^3+b_tK1*(x-K1)^3 , range(15 30)
lcolor(black)  ||  function
y=b_cons+b_t*x+b_t_sq*x^2+b_t_cu*x^3+b_tK1*(x-K1)^3+b_tK2*(x-K2)^3 ,
range(30 45) lcolor(black) ||  function
y=b_cons+b_t*x+b_t_sq*x^2+b_t_cu*x^3+b_tK1*(x-K1)^3+b_tK2*(x-K2)^3+b_tK3*(x-K3)^3
, range(45 60) lcolor(black) , legend(off) ytitle("height")
xtitle("year") xlabel(1 "1740" 21 "1760" 41 "1780" 61 "1800")

*! -------------------------------------------------------- *!

Does anybody know how to calculate the confidence bounds for this regression?
I appreciate your help!

Thank you very much...

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