全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
8237 4
2006-05-20
本人初学stata, 望哪位高人指点迷津!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2006-5-20 09:23:00

有命令啊 Nlogit,看帮组吧。

---------------------------------------------------------------------------------------
help for nlogit, nlogitgen, nlogittree manual: [R] nlogit
dialogs: nlogit predict
nlogitgen nlogittree
---------------------------------------------------------------------------------------

Maximum-likelihood nested logit estimation

Fit model

nlogit depvar (altsetvarB = indepvarsB) [... (altsetvar2 = indepvars2)
(altsetvar1 = indepvars1)] [weight] [if exp] [in range]
, group(varname) [ notree nolabel clogit level(#) nolog robust
ivconstraints(string) constraints(numlist) d1 maximize_options ]

where

depvar is a dichotomous variable coded as 0 for not selected
alternatives and 1 for the selected alternative.
altsetvarB is a categorical variable that identifies the bottom, or
final, set of all alternatives.
indepvarsB are the attributes of the bottom-level alternatives (absolute
or perceived) and possibly interactions of individual
attributes with the bottom-level alternatives.
altsetvar2 is a categorical variable that identifies the second-level set
of alternatives -- these must be mutually exclusive groups of
the third-level alternatives.
indepvars2 are the attributes of the second-level alternatives (absolute
or perceived) and possibly interactions of individual
attributes with the first second-level alternatives.
altsetvar1 is a categorical variable that identifies the top- or
first-level set of alternatives -- these alternatives must be
mutually exclusive groups of the second-level alternatives.
indepvars1 are the attributes of the first-level alternatives -- either
of an alternative alone (absolute) or as the alternative is
perceived by the chooser (perceived) -- and possibly
interactions of individual attributes with the first-level
alternatives.


Data setup

nlogitgen newvar = varname (branchlist) [, nolog]

where branchlist is
branch, branch [, branch ...]

branch is
[label:] outcome [| outcome [| outcome ...] ]

and outcome is either a numerical value of the variable specified as varname,
or the value label associated with the numerical value. For instance,

. nlogitgen type = restaurant(fast: 1 | 2, family: 3 | 4 | 5,
fancy: 6 | 7)


Display tree structure

nlogittree varlist [, nolabel ]


by ... : may be used with nlogit; see help by.

fweights and iweights are allowed; see help weights, but they are interpreted to
apply to groups as a whole and not to individual observations.

nlogit shares the features of all estimation commands; see help estcom.


The syntax of predict following nlogit is

predict [type] newvarname [if exp] [in range] [, statistic ]

where statistic is

pb predicted probability of choosing bottom-level, or choice-set,
alternatives -- each alternative identified by altsetvarB; the
default.
p1 predicted probability of choosing first-level alternatives -- each
alternative identified by altsetvar1.
p2 predicted probability of choosing second-level alternatives -- each
choice identified by altsetvar2.
...
p# predicted probability of choosing #-level alternatives -- each
alternative identified by altsetvar#.
xbb linear prediction for the bottom-level alternatives.
xb1 linear prediction for the first-level alternatives.
xb2 linear prediction for the second-level alternatives.
...
xb# linear prediction for the #-level alternatives.
condpb Pr(each bottom alternative | alternative is available after all
earlier choices).
condp1 Pr(each level 1 alternative) = p1.
condp2 Pr(each level 2 alternative | alternative is available after level 1
decision).
condp3 Pr(each level 3 alternative | alternative is available after stage 1
and stage 2 decisions).
...
condp# Pr(each level # alternative | alternative is available after all
previous stage decisions).
ivb inclusive value for the bottom-level alternatives.
iv1 inclusive value for the first-level alternatives.
iv2 inclusive value for the second-level alternatives.
...
iv# inclusive value for the #-level alternatives.

The inclusive value for the first-level alternatives is not used in the fitting
of the model, therefore, it is not calculated.

These statistics are available both in and out of sample; type "predict ... if
e(sample) ..." if wanted only for the estimation sample.


Description

nlogit fits a nested logit model using full maximum-likelihood. The model may
contain one or more levels. For a single-level model, nlogit fits the same model
as clogit; see help clogit.

nlogitgen generates a new categorical variable based on the specification of the
branches. For instance,

. nlogitgen type = restaurant(fast: 1 | 2, family: 3 | 4 | 5, fancy: 6 | 7)

is equivalent to

. gen type = 1 if restaurant == 1 | restaurant == 2
. replace type = 2 if restaurant == 3 | restaurant == 4 | restaurant== 5
. replace type = 3 if restaurant == 6 | restaurant == 7
. label define lb_type 1 fast 2 family 3 fancy
. label value type lb_type

nlogittree displays the tree structure based on the varlist. Note that the
bottom level should be specified first. For instance,

. nlogittree type restaurant


Options

group(varname) is not optional; it specifies the identifier variable for the
groups.

notree specifies that the tree structure of the nested logit model is not to be
displayed.

nolabel causes the numeric codes rather than the label values to be displayed in
the tree structure of the nested logit model.

clogit specifies that the initial values obtained from clogit are to be
displayed.

level(#) specifies the confidence level, in percent, for confidence intervals of
the coefficients; see help level.

nolog suppresses the iteration log.

robust specifies that the Huber/White/sandwich estimator of variance is to be
used in place of the traditional calculation; see [U] 23.14 Obtaining robust
variance estimates. This option is not allowed when the specified model
contains more than 3 levels.

ivconstraints(string) specifies the linear constraints of the inclusive value
parameters. One can constrain inclusive value parameters to be equal to each
other, equal to fixed values, etc. Inclusive value parameters are referred
to by the corresponding level labels; for instance, ivconstraints(fast =
family) or ivconstraints(fast=1).

constraints(numlist) specifies the linear constraints to be applied during
estimation. Constraints are defined using the constraint command and are
numbered; see help constraint. The default is to perform unconstrained
estimation.

maximize_options control the maximization process; see help maximize. You will
likely never need to specify any of the maximize options except for
iterate(0) and possibly difficult. If the iteration log shows many "not
concave" messages and is taking many iterations to converge, you may want to
use the difficult option to help it converge in fewer steps.


Options for predict

Consider a nested logit model with 3 levels: P(ijk) = P(k|ij)*P(j|i)*P(i).

pb, the default, calculates the probability of choosing bottom-level
alternatives, pb = P(ijk).

p1, calculates the probability of choosing first-level alternatives, p1 = P(i).

p2, calculates the probability of choosing second-level alternatives, p2 = P(ij)
= P(j|i)*P(i).

xbb, calculates the linear prediction for the bottom-level alternatives.

xb1, calculates the linear prediction for the first-level alternatives.

xb2, calculates the linear prediction for the second-level alternatives.

condpb, condpb = P(k|ij).

condp1, condp1 = P(i).

condp2, condp2 = P(j|i).

ivb, calculates the inclusive value for the bottom-level alternatives: ivb =
ln(sum(exp(xbb))), where xbb is the linear prediction for the bottom-level
alternatives.

iv2, calculates the inclusive value for the second-level alternatives: iv2 =
ln(sum(exp(xb2 + tau_j*ivb))), where xb2 is the linear prediction for the
second-level alternatives, ivb is the inclusive value for the bottom-level
alternatives, and tau_j are the parameters for the inclusive value.


Examples

Generate a new categorical variable named "type" that identifies the first-level
set of alternatives based on the variable named "restaurant".

. nlogitgen type = restaurant(fast: Freebirds | MamasPizza, family:
CafeEccell | LosNortenos | WingsNmore, fancy: Christophers | MadCows)

The tree structure implied by these two variables can be examined using
nlogittree.

. nlogittree restaurant type

Fit the nested logit model.

. nlogit chosen (restaurant = cost rating distance) (type = incFast incFancy
kidFast kidFancy), group(family_id)

. nlogit chosen (restaurant = cost rating distance) (type = incFast incFancy
kidFast kidFancy), group(family_id) ivc(fast=1, family=1, fancy=1)


Also see

Manual: [U] 23 Estimation and post-estimation commands,
[U] 29 Overview of Stata estimation commands,
[R] nlogit

Online: help for estcom, postest; clogit, constraint, glogit, logistic, logit,
ml, mlogit, ologit, oprobit, probit, xtgee, xtprobit

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-11-13 22:10:00
wo ye  kankan
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-11-20 18:35:12
nested logit的数据格式应该是怎样的?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-11-20 18:50:46
下面是stata中nlogit的例子。你可以去stata主页下载 restaurant.dta文件,看看那个数据的格式不就知道了吗。

Examples

    Generate a new categorical variable named type that identifies the first-level set of alternatives based on
    the variable named restaurant.

        . webuse restaurant

        . nlogitgen type = restaurant(fast: Freebirds | MamasPizza, family:  CafeEccell | LosNortenos |
            WingsNmore, fancy: Christophers | MadCows)

    The tree structure implied by these two variables can be examined using nlogittree.

        . nlogittree restaurant type, choice(chosen)

        . nlogit chosen cost distance rating || type: income kids, base(family) || restaurant:, noconst
            case(family_id)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群