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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Re: prvalue with many dummy variables


From   "Vitorino, Maria Ana" <vitorino@wharton.upenn.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: prvalue with many dummy variables
Date   Mon, 12 Mar 2012 00:50:25 +0000

Dear Eric,

Thanks so much for the help!

Ana

On Mar 11, 2012, at 11:32 AM, Eric Booth wrote:

> <>
> I agree with Joseph Coveney that -margins- is the way to go.
> If you want to stick with -prvalue- (from -spost-), you can 'build' the command in a macro, instead of writing it all out,  with something like:
> 
> ****************!
> forval n = 2/20 {
>     loc j  `" `j' school_d`n'=0"'
>     }
> di `"`j'"'
> **
> prvalue x(sex=1 age=20 school_d1=1 `j' )
> ****************!
> 
> EAB
> __
> Eric A. Booth
> Public Policy Research Institute 
> Texas A&M University
> ebooth@ppri.tamu.edu
> +979.845.6754
> 
> On Mar 11, 2012, at 1:35 AM, Joseph Coveney wrote:
> 
>> Maria Ana Vitorino wrote:
>> 
>> If I fit a logit model with many dummy variables such as:
>> 
>> logit pass sex age school_d*
>> 
>> where school_d* includes dummies for schools numbered from 1 to 20, i.e.
>> school_d1, school_d2, ,,,, school_d20
>> 
>> how can I calculate a predicted probability without having to specify values for
>> all the 19 schools that take value 0?
>> 
>> For example, suppose I want to do something like
>> prvalue x(sex=1 age=20 school_d1=1 school_d2=0 school_d3=0  etc)
>> 
>> Is there a way of not having to write  in the command line above that
>> school_d[i]=0 for every i other than 1?
>> 
>> --------------------------------------------------------------------------------
>> 
>> The easiest way would be to use factor variables and -margins-.  It's
>> illustrated below.  An alternative that works for older version of Stata is to
>> use -lincom- and then transform the linear prediction.  That's also illustrated
>> below.  (The first part just creates a fictional dataset to use for
>> illustration.)
>> 
>> Joseph Coveney
>> 
>> version 11.2
>> 
>> clear *
>> set more off
>> set seed `=date("2012-03-10", "YMD")'
>> quietly set obs 20
>> generate byte school = _n
>> generate byte count = 50
>> expand count
>> generate byte pass = 0.5 < runiform()
>> generate byte sex = 0.5 < runiform()
>> generate byte age = 18 + floor(4 * runiform())
>> logit pass i.sex c.age i.school, nolog
>> 
>> *
>> * Easiest
>> *
>> margins , at(sex=1 age=20 school=1)
>> 
>> *
>> * Alternative
>> *
>> quietly lincom _b[_cons] + _b[age] * 20 + _b[1.sex]
>> display in smcl as text "Pr(pass | sex == 1 & " ///
>>   "age == 20 & school == 1) = " ///
>>   as result %05.3f invlogit(r(estimate))
>> 
>> exit
>> 
>> 
>> *
>> *   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/


*
*   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/


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