help for case2alt03Nov2005

Convert data from one observation per case to one observation per alternative per case

case2alt ,
{choice(varname) | rank(stubname)}
[alt(stubnames)
casevars(varlist)
case(varname)
generate(newvar)
replace
altnum(varname)
nonames]

Description

case2alt is intended to be used to configure data for the estimation of estimation
of regression models for alternative-specific data, such as clogit,
rologit or asmprobit. case2alt presumes that you have data
where each observation corresponds to an individual case and that you want to convert
the data to the form in which each observation corresponds to an alternative for a specific case.

Imagine that you have data with an outcome that has four alternatives, with values 1, 2, 3 and 8.
case2alt will reshape the data so that there are n*4 observations. If you specify an
identifying variable with the casevars() option, this variable will continue to identify
unique cases; otherwise, new variable _id will identify cases.

A new variable, called either _altnum or the name specified in altnum(),
will identify the alternatives within a case. Additionally, however, case2alt
will create dummy variables yvalue that also identify alternatives.
In our example the new dummy variables y1, y2, y3 and y8 will be created.
Interactions will also be created with these dummies and any variables
specified in case(). For the variable educ, case2alt will create
variables y1_educ, y2_educ, y3_educ, and y8_educ.

If we have simple choice variable, then case2alt will create an outcome
variable based on y() that contains 1 in the observation corresponding to
the selected alternative and 0 for other alternatives. We can specify the name of
this new outcome variable using the gen() option, or we can have it be the
same as y() using the replace option, or (by default) we
can have it be named choice.

After using case2alt, we would be able to estimate models like clogit by typing, e.g.,:

. clogit choice y1* y2* y3*, group(_id)

Alternative-specific variables are specified using the alt() option.
The contents of alt() should be stubnames, corresponding to a series
of variables that contain the alternative-specific values.
Specifying alt(time), in our example, would imply that there are
variables time1, time2, time3 and time8 in our case-level data.

Case-specific variables are specified using the casevars() option,
where the contents should be a varlist. Neither the outcome nor id variable
should be included in casevars().

If we have ranked data, we can specify the ranked outcome with the
rank() outcome. The content of rank should again be a stubname.
Specifying rank(rank) in our example would assume there are
variables rank1, rank2, rank3, rank8 that contain the relevant information
on the ranks of each alternative.

Options

choice(varname) or rank(stubname) is required. varname is the
variable that indicates the value of the selected alternative.
In the case of ranked outcome, stubname with rank() will contain
the stub for the names of variables that contain information about ranks of alternatives.

case(varname) indicates the variable, either existing or to be
created, that identifies individual cases.
If varname is unspecified, a new variable named _id will be created.

alt(stubnames) contains the stubnames for
alternative-specific variables. This requires that variables stubname# exist
for each value of an alternative.

casevars(varlist) contains the names of the case-specific variables
(not including the id or outcome variable).

generate(newvar) and replace are used to name the variable that
contain 1 for the selected alternative and 0 for non-selected alternatives.
The variable will be named newvar if newvar is specified; the name of
the variable specified in y() if replace is specified; and will be named choice otherwise.
In the case of ranked data, the ranks will be contained in variable specified as the
stub in yrank() and generate() or replace will be ignored.

altnum(varname) indicates the name of the new variable used to indicate
the alternatives. _altnum will be used if altnum() is not specified.

nonames indicates that the case-specific interactions should be named
y# instead of using the value labels of the outcome variable.

Example

. use "http://www.stata-press.com/data/lfr/nomocc2.dta", clear

. mlogit occ white ed exper

. case2alt, choice(ed) casevars(white ed exper) replace nonames

. clogit occ y1* y2* y3* y4*, group(_id)

. case2alt, rank(rank92) casevars(hntest) alt(rank04) case(id)

Authors

Jeremy Freese and J. Scott Long
www.indiana.edu/~jslsoc/spost.htm
spostsup@indiana.edu