Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: interaction graph


From   "Airey, David C" <david.airey@vanderbilt.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: interaction graph
Date   Wed, 23 Feb 2011 08:07:10 -0600

.

Beautiful, Maarten!

-Dave

--- On Wed, Feb 23, 2011 Fabio Zona wrote:
> > However, what command should I use if I have
> > a) a quadratic form (i.e.,   x  +  x_square)
> > b) the moderator is a continous variable (not a
> > dummy), and it is multiplied by both x  and  x-square ??

--- On Wed, 23/2/11, Nick Cox wrote:
> generating predictions for a few fixed values of
> your moderator might produce an adequate graph.

In addition, I like to emphasize the ordinal nature of the 
different lines by displaying them in ever darker tones.
A nice resource for choosing your colors is:
<
http://colorbrewer2.org/
>

To make Nick's suggestion and my minor additional note more 
concrete, consider the example below:

*------------------------- begin example ---------------------
sysuse auto, clear

// estimate the model
reg price c.mpg##c.weight##c.weight i.foreign

// collect some information about mpg
sum mpg
local m = r(mean)
local sd = r(sd)

// we are going to change the data, so we preserve it first
preserve

// fix the other explanatory variables
// In this case we only look at US ("domestic") cars
replace foreign = 0

// predict the price while fixing mpg at different values
replace mpg = `m'
predict yhatm

replace mpg = `m' - `sd'
predict yhatl

replace mpg = `m' - 2*`sd'
predict yhatll

replace mpg = `m' + `sd'
predict yhath

replace mpg = `m' + 2*`sd'
predict yhathh

// nicer display of large numbers 1,000 instead of 1000
format yhat* %8.0gc

// create graph
sort weight
twoway line yhatll yhatl yhatm yhath yhathh weight, ///
       title("predicted price for US cars")         ///
       ytitle("predicted price (US {c S|})")        /// 
       lpattern(solid solid solid solid solid)      ///
       lcolor("255 255 204"                         ///
              "161 218 180"                         ///
              " 65 182 196"                         /// 
              " 44 127 184"                         ///   
              " 37  52 148" )                       ///
       legend( order( - "mpg"                       ///
                      1 "mean-2*sd"                 ///
                      2 "mean-1*sd"                 ///
                      3 "mean"                      ///
                      4 "mean+1*sd"                 ///
                      5 "mean+2*sd" ))

// get our original data back
restore

*--------------------------- end example --------------------
(For more on examples I sent to the Statalist see: 

http://www.maartenbuis.nl/example_faq
 )

Hope this helps,
Maarten



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index