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

Re: st: Plotting 3way interactions

From   Philip Ender <>
Subject   Re: st: Plotting 3way interactions
Date   Mon, 17 Aug 2009 17:24:39 -0700

I believe that Kris is referring to a FAQ page posted on ATS' Stata
Faq page.  I am working with him off line to see if we can solve the
problem.  When (if) we find the solution I'll report back to

Phil Ender
Statistical Consulting Group
UCLA  Academic Technology Services

17 Aug 2009, Kris Anderson wrote>>


I am struggling with a final line of code on plotting a 3way
interaction in Stata. I can run everything except the two-way code for
the scatter plot (I added ** to identify the line below). What I get
is a mix of lines, not the lovely interaction plot from the FAQ. Any

regress avgdrink age sex gradedich white hisp csocanx caffil cpn SAF
SP AP SAP if currentdrinker > 0
sum csocanx
sum csocanx
global hi=r(max)
global lo=r(min)
sum caffil
global HAF=r(mean)+r(sd)
global LAF=r(mean)-r(sd)
sum cpn
global HPN=r(mean) +r(sd)
global LPN=r(mean) -r(sd)
sum age
global mage=r(mean)
sum gradedich
global mgrade=r(mean)
sum white
global mwhite=r(mean)
sum hisp
global mhisp=r(mean)
global HPNHAF "csocanx + ($HPN)*SP + ($HAF)*SAF + ($HPN)*($HAF)*SAP"
global HPNLAF "csocanx + ($HPN)*SP + ($LAF)*SAF + ($HPN)*($LAF)*SAP"
global LPNHAF "csocanx + ($LPN)*SP + ($HAF)*SAF + ($LPN)*($HAF)*SAP"
global LPNLAF "csocanx + ($LPN)*SP + ($LAF)*SAF + ($LPN)*($LAF)*SAP"
lincom $HPNHAF
global b1 = r(estimate)
lincom $HPNLAF
global b2 = r(estimate)
lincom $LPNHAF
global b3 = r(estimate)
lincom $LPNLAF
global b4 = r(estimate)
lincom _cons + $HPN*cpn + $HAF*caffil + $HPN*$HAF*AP + $mage*age +
$mgrade*gradedich + $mwhite*white
global c1 = r(estimate)
lincom _cons + $HPN*cpn + $LAF*caffil + $HPN*$LAF*AP + $mage*age +
$mgrade*gradedich + $mwhite*white
global c2 = r(estimate)
lincom _cons + $LPN*cpn + $HAF*caffil + $LPN*$HAF*AP + $mage*age +
$mgrade*gradedich + $mwhite*white
global c3 = r(estimate)
lincom _cons + $LPN*cpn + $LAF*caffil + $LPN*$LAF*AP + $mage*age +
$mgrade*gradedich + $mwhite*white
global c4 = r(estimate)
***twoway(function y=$c1+$b1*csocanx, range($lo $hi))(function
y=$c2+$b2*csocanx, range($lo $hi))(function y=$c3+$b3*csocanx,
range($lo $hi))(function y=$c4+$b4*csocanx, range($lo $hi))(scatter
avgdrink cpn, msym(oh) jitter(3)), legend(order(1 "1 HPNHAF" 2 "2
HPNLAF" 3 "3 LAPHAF" 4 "4 LAPLAF")) xtitle (X) ytitle(Y)
name(con3wayb, replace)
lincom ($HPNHAF)- ($HPNLAF)
lincom ($HPNHAF)- ($LPNHAF)
lincom ($HPNLAF)- ($LPNLAF)
lincom ($LPNHAF)- ($LPNLAF)
lincom ($HPNHAF)- ($LPNLAF)
lincom ($HPNLAF)- ($LPNHAF)

Thank you.
*   For searches and help try:

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