Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Jorge Eduardo Pérez Pérez <jorge_perez@brown.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
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 <writeon4truth2@msn.com> 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: jorge_perez@brown.edu >> Date: Wed, 20 Nov 2013 21:51:38 -0500 >> Subject: Re: st: Post-regression graph >> To: statalist@hsphsun2.harvard.edu >> >> 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 <writeon4truth2@msn.com> 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/