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: Contour plot help

From   Bill Rising <>
To   Stata Listserv <>
Subject   Re: st: Contour plot help
Date   Tue, 26 Feb 2013 17:57:49 -0600

Carolina Echevarria <> asked about making a contour plot from the results of -margins- similar to that shown on the last slide of

She was running a -logit-, followed by -margins-, followed by -estimates store-

> quietly logit outcome varX varY 
> margins, at( varX=(1(0.5)5))
> I try to save the margins using estimates store, but didnt work

To get the two dimensions for the x and y variables in the contour plot, she needs to also have some values for varY (see below).

Instead of using -estimates store- to create a dataset for the graph she needs to use the undocumented function _marg_save, which is used to create a dataset from the margins.

Here are a few lines of code which put the margins in the dataset named forContour.dta, which I am happy to overwrite, as its only purpose is to make the graph. I made up values for the varY variable, but she should use useful ones:

  margins, at( varX=(1(0.5)5) varY=(10(1)20))
  _marg_save, saving(forContour, replace) 
  preserve // so the original dataset can be recovered
  use forContour, clear
  twoway contour _merge _at1 _at2, ccuts(0(0.05)0.5)  
  restore // to recover the original dataset

For future reference: here is a zip file containing the do-file used to make the graph in the talk:


Bill Rising  
*   For searches and help try:

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