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]

From |
Jorge Eduardo Pérez Pérez <[email protected]> |

To |
"[email protected]" <[email protected]> |

Subject |
Re: st: Post-regression graph |

Date |
Wed, 20 Nov 2013 23:01:21 -0500 |

The command -twoway qfit y x- estimates the quadratic regression model -reg y x x^2- and plots the predicted relationship between y and x from the estimated model. It will do so even if you have not estimated any model beforehand. After you run the regression model, the variable e(sample) becomes 1 for observations that were included in estimation of the model and 0 otherwise. So if you write -twoway qfit y x- if e(sample), after estimating a quadratic regression model. Stata will estimate a quadratic model on the sample that was used for the regression model. The model and the graph will be equivalent. This would not necessarily be the case if you don't use e(sample), because then your model and your graph could be using different samples. If you actually want to see the graph arising from your initial model, you can graph the prediction against the independent variable: sysuse auto, clear gen mpg2=mpg*mpg reg price mpg mpg2 predict pricehat line pricehat mpg, sort Or graph the function implied by the model twoway function y = _b[_cons] +_b[mpg]*x + _b[mpg2]*x^2, range(10 40) If you want a model and a graph for different race groups, you should estimate a model for each group, or estimate a model with interactions. For example. here I estimate two models and plot both lines sysuse auto, clear gen mpg2=mpg*mpg reg price mpg mpg2 if foreign predict pricehat1 reg price mpg mpg2 if !foreign predict pricehat2 line pricehat1 pricehat2 mpg, sort legend(label(1 "Foreign") label(2 "Domestic")) -------------------------------------------- Jorge Eduardo Pérez Pérez Graduate Student Department of Economics Brown University On Wed, Nov 20, 2013 at 10:14 PM, David Torres <[email protected]> wrote: > Thanks, Jorge. > > But please tell me why I can get a graph using that command even when I haven't run a regression model? And the fitted line looks exactly the same as it does when I run the regression and then add the "if e(sample)"? I'm terribly confused. > > Also, is the restriction issue a problem if I want to graph a different line for different races/ethnic groups? > > Thanks again, > Diego > > > ---------------------------------------- >> From: [email protected] >> Date: Wed, 20 Nov 2013 21:51:38 -0500 >> Subject: Re: st: Post-regression graph >> To: [email protected] >> >> I think you want to use e(sample) >> >> For example, if you run a quadratic mode on a subsamplel: >> >> sysuse auto, clear >> gen mpg2=mpg*mpg >> reg price mpg mpg2 if foreign >> >> Then the graph of this model would be: >> >> twoway qfit price mpg if e(sample) >> >> You may restrict your graph to a smaller subsample with another >> condition, for example: >> >> twoway qfit price mpg if e(sample)&turn>5 >> >> But this graph does not correspond to the model you estimated on the >> first place. >> >> >> -------------------------------------------- >> Jorge Eduardo Pérez Pérez >> Graduate Student >> Department of Economics >> Brown University >> >> >> On Wed, Nov 20, 2013 at 9:22 PM, David Torres <[email protected]> wrote: >>> I'm trying to get a nonlinear regression line after estimating a model. The following is the command I'm using (and the error returned). >>> >>> . graph twoway qfit srsc year if `e(model)'&white==1 >>> g2sls not found >>> r(111); >>> >>> >>> What specifically am I doing wrong here? If I drop the `e(model)' I can get a line, but I'm afraid it's not taking into account the actual model I want to graph. >>> >>> Thanks in advance, >>> Diego >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/faqs/resources/statalist-faq/ >>> * http://www.ats.ucla.edu/stat/stata/ >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/statalist-faq/ >> * http://www.ats.ucla.edu/stat/stata/ > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Post-regression graph***From:*David Torres <[email protected]>

**Re: st: Post-regression graph***From:*Jorge Eduardo Pérez Pérez <[email protected]>

**RE: st: Post-regression graph***From:*David Torres <[email protected]>

- Prev by Date:
**Re: st: Need Help with Stata Programming** - Next by Date:
**st: 0 lag command for Pooled Mean Group (PMG) Estimator** - Previous by thread:
**RE: st: Post-regression graph** - Next by thread:
**st: 0 lag command for Pooled Mean Group (PMG) Estimator** - Index(es):