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]

st: Re: prvalue with many dummy variables

From   "Joseph Coveney" <>
To   <>
Subject   st: Re: prvalue with many dummy variables
Date   Sun, 11 Mar 2012 16:35:17 +0900

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

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 c.age, nolog

* Easiest
margins , at(sex=1 age=20 school=1)

* Alternative
quietly lincom _b[_cons] + _b[age] * 20 + _b[]
display in smcl as text "Pr(pass | sex == 1 & " ///
    "age == 20 & school == 1) = " ///
    as result %05.3f invlogit(r(estimate))


*   For searches and help try:

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