Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: contrasts

From   Jeffrey Pitblado <>
Subject   Re: st: contrasts
Date   Mon, 01 Oct 2012 21:32:24 -0500

Nikolaos Pandis <> originally asked about
plotting margin contrasts, but I jumped to pairwise comparisons of
margins when I noticed the third comparison in the original email.
Nick's follow-up comment on my reply was:

> Thank you for the suggestion.

marginsplot after :

margins r.wiretype,contrast

looks neater compared to:

margins wiretype, pwcompare

Nick can get -margins- to plot any number of contrasts of margins,
the trick is employing user-defined contrasts.  Here is a rework
of Nick's original example that also includes the 3 vs 2 contrast:

	margins {wiretype -1  1 0} /// 2 vs 1
		{wiretype -1  0 1} /// 3 vs 1
		{wiretype  0 -1 1}  // 3 vs 2

While user-defined contrasts require more from the user in order to
specify them, user-defined contrasts also give the user the most amount
of control.

--Jeff Pitblado


Here the example code I was playing with while thinking about
Nick's query:

sysuse auto

gen fac = (rep<4) + 2*(rep==4) + 3*(rep==5)

keep if fac

regress mpg i.fac

margins r.fac
marginsplot, name(contrast)

margins fac, pwcompare
marginsplot, name(pwcompare)

margins	{fac -1  1 0}	///
	{fac -1  0 1}	///
	{fac  0 -1 1}
marginsplot, name(user)

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index