Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: mkspline and reg

From   "Maarten Buis" <[email protected]>
To   <[email protected]>
Subject   st: RE: mkspline and reg
Date   Wed, 1 Nov 2006 10:21:58 +0100

One way to see if your approach makes sense is to create predicted values, graph them and 
see if they make sense, like in the example below. I think it follows your procedure and the 
graphs look fine.


*-------------- begin example ------------
sysuse auto, clear
mkspline mpg1 20 mpg2=mpg

gen forXmpg1 = foreign*mpg1
gen forXmpg2 = foreign*mpg2
reg price mpg1 mpg2 forXmpg1 forXmpg2 foreign

predict pricehat1
twoway line pricehat1 mpg if foreign==0, sort  || /*
    */ line pricehat1 mpg if foreign==1, sort  /*
    */ ytitle("predicted price") name(a) /*
    */ legend(label(1 "domestic") label(2 "foreign"))

gen mpg1b = mpg1 - 12
gen forXmpg1b = foreign*mpg1b
reg price mpg1b mpg2 forXmpg1b forXmpg2 foreign
predict pricehat2
twoway line pricehat2 mpg if foreign==0, sort  || /*
    */ line pricehat2 mpg if foreign==1, sort  /*
    */ ytitle("predicted price") name(b) /*
    */ legend(label(1 "domestic") label(2 "foreign"))
*--------------- end example ---------------

Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of stata_user stata_user
Sent: dinsdag 31 oktober 2006 23:28
To: [email protected]
Subject: st: mkspline and reg

I 've a variable age which takes values from 20 to 60,
I have an outcome y and a dummy variable represnting gender

I would like to fit a regresion model using linear splines, including an
interraction effect

I want to test if there are two different slopes before 40 and after 40, and
I am also interested on the intercept , I consider the following approach

1/ First create linear splines

mkspline age1 40 age2 = age

2/Second  in order to have intercept at age=40

generate age1a = age1 -40

I fit a regression model

xi: regress y*age1a*age2

Could you please comment on this approach?


*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index