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, **statalist.org** is already up and running.

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

From |
"Vitorino, Maria Ana" <vitorino@wharton.upenn.edu> |

To |
"<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Calculating predicted probabilities at a given value of one of the independent variables |

Date |
Thu, 27 Oct 2011 04:55:18 +0000 |

Thanks for the detailed explanation. Indeed in my case there is no missing data so the results should be the same. But, like you said, it's good to keep in mind this distinction for future reference. Thanks again! Ana On Oct 27, 2011, at 12:48 AM, "Richard Williams" <richardwilliams.ndu@gmail.com> wrote: > At 10:05 PM 10/26/2011, Vitorino, Maria Ana wrote: >> Thanks!! But the results should be the same as in your previous suggestion, right? Or am I missing something? > > When using the predict command, Stata will usually, if possible, generate predictions for the out of sample cases, i.e. the cases that were not used in the original estimation. So, for example, suppose you have complete data on all the x variables but 50 cases are missing on y. The estimation command will exclude the 50 missing cases. But a subsequent predict command will generate predicted values for every case, because every case has complete data on the x's. By including stuff like -if e(sample)-, you only generate predicted values for those cases used by the estimation command, i.e. the 50 cases that were missing on y will have missing values on the variables computed by predict. > > Or, suppose the original estimation command included a qualifier like -if male==1-, i.e. you were only analyzing males. A subsequent predict command would also compute predicted values for females unless you added an -if e(sample)- qualifier. > > My original coding also created the possibility that a case that was originally excluded from the estimation because male was missing would now get included in the predictions because I set xmale=0 for all cases. > > Now, there are often situations where you want out of sample predictions. e.g. maybe those 50 cases are missing y because for them y is something that will happen in the near future and you want to predict what the value of y will be. If that is what you want, then stick with my original code. But if you only want predicted values for the cases used in the estimation, you should go with something like my tweaked example. > > The two sets of code would produce identical results if there is no missing data and you are not restricting the sample selection in any way. But if you know you want to limit predictions to in-sample it is probably a good idea to just get in the habit of including -if e(sample)- in your coding just to be safe. > >> Ana >> >> >> On Oct 26, 2011, at 10:53 PM, "Richard Williams" <richardwilliams.ndu@gmail.com> wrote: >> >> > At 06:06 PM 10/26/2011, Maria Ana Vitorino wrote: >> >> Dear Statalist users, >> >> >> >> I would like to calculate some predicted probabilities after fitting a >> >> multinomial logit model (asclogit). But, the twist is that I would >> >> like to calculate these fitted values for a given level of one of the >> >> independent variables. Namely, I would like to set one of the Xs to >> >> zero when computing the predicted probability (but not in the >> >> estimation). >> >> What would be the best way of going about this? Would it make sense to >> >> do it in 2 steps? In the first step use "predict xb" and in the >> >> second step remove the component of xb that I'm not interested and >> >> calculate the probability using "gen" and the logit formula? >> >> Or is there a better way? >> > >> > I am going to slightly tweak my earlier advice. Assuming you only want in-sample predictions, >> > >> > webuse sysdsn1, clear >> > clonevar xmale = male >> > mlogit insure age i.xmale nonwhite i.site >> > predict p1 p2 p3 if e(sample) >> > replace xmale = 0 if !missing(xmale) >> > predict pp1 pp2 pp3 if e(sample) >> > >> > >> > ------------------------------------------- >> > Richard Williams, Notre Dame Dept of Sociology >> > OFFICE: (574)631-6668, (574)631-6463 >> > HOME: (574)289-5227 >> > EMAIL: Richard.A.Williams.5@ND.Edu >> > WWW: http://www.nd.edu/~rwilliam >> > >> > * >> > * 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/ >> >> * >> * 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/ > > ------------------------------------------- > Richard Williams, Notre Dame Dept of Sociology > OFFICE: (574)631-6668, (574)631-6463 > HOME: (574)289-5227 > EMAIL: Richard.A.Williams.5@ND.Edu > WWW: http://www.nd.edu/~rwilliam > > * > * 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/ * * 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/

**References**:**st: Calculating predicted probabilities at a given value of one of the independent variables***From:*Maria Ana Vitorino <vitorino@wharton.upenn.edu>

**Re: st: Calculating predicted probabilities at a given value of one of the independent variables***From:*Richard Williams <richardwilliams.ndu@gmail.com>

**Re: st: Calculating predicted probabilities at a given value of one of the independent variables***From:*"Vitorino, Maria Ana" <vitorino@wharton.upenn.edu>

**Re: st: Calculating predicted probabilities at a given value of one of the independent variables***From:*Richard Williams <richardwilliams.ndu@gmail.com>

- Prev by Date:
**Re: st: Calculating predicted probabilities at a given value of one of the independent variables** - Next by Date:
**Re: st: Calculating predicted probabilities at a given value of one of the independent variables** - Previous by thread:
**Re: st: Calculating predicted probabilities at a given value of one of the independent variables** - Next by thread:
**Re: st: Calculating predicted probabilities at a given value of one of the independent variables** - Index(es):