全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
72401 18
2013-10-14
比如说 X、Y两个自变量,若要在stata12中进行回归时建立交互项,那么交互项该如何表示
二维码

扫码加我 拉你入群

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

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

全部回复
2013-10-14 18:27:14
建立新变量

gen z=x*y
二维码

扫码加我 拉你入群

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

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

2013-10-14 19:49:58

Title

    [U] 11.4.3 Factor variables


Description

    Factor variables are extensions of varlists of existing variables.  When a command allows factor variables, in
    addition to typing variable names from your data, you can type factor variables, which might look like

        i.varname

        i.varname#i.varname

        i.varname#i.varname#i.varname

        i.varname##i.varname

        i.varname##i.varname##i.varname

    Factor variables create indicator variables from categorical variables, interactions of indicators of categorical
    variables, interactions of categorical and continuous variables, and interactions of continuous variables
    (polynomials).  They are allowed with most estimation and postestimation commands, along with a few other
    commands.

    There are four factor-variable operators:

         Operator  Description
         -------------------------------------------------------------------------------------------------------------
         i.        unary operator to specify indicators
         c.        unary operator to treat as continuous
         #         binary operator to specify interactions
         ##        binary operator to specify factorial interactions
         -------------------------------------------------------------------------------------------------------------

    The indicators and interactions created by factor-variable operators are referred to as virtual variables.  They
    act like variables in varlists but do not exist in the dataset.

    Categorical variables to which factor-variable operators are applied must contain nonnegative integers with values
    in the range 0 to 32,740, inclusive.

    Factor variables may be combined with the L. and F. time-series operators.


Remarks

    Remarks are presented under the following headings:

        Basic examples
        Base levels
        Selecting levels
        Applying operators to a group of variables


Basic examples

    Here are some examples of use of the operators:

         Factor            
         specification     Result
         -------------------------------------------------------------------------------------------------------------
         i.group           indicators for levels of group

         i.group#i.sex     indicators for each combination of levels of group and sex, a two-way interaction

         group#sex         same as i.group#i.sex

         group#sex#arm     indicators for each combination of levels of group, sex, and arm, a three-way interaction

         group##sex        same as i.group i.sex group#sex

         group##sex##arm   same as i.group i.sex i.arm group#sex group#arm sex#arm group#sex#arm

         sex#c.age         two variables -- age for males and 0 elsewhere, and age for females and 0 elsewhere; if age
                             is also in the model, one of the two virtual variables will be treated as a base

         sex##c.age        same as i.sex age sex#c.age

         c.age             same as age

         c.age#c.age       age squared

         c.age#c.age#c.age age cubed
         -------------------------------------------------------------------------------------------------------------


Base levels

    You can specify the base level of a factor variable by using the ib. operator.  The syntax is

           Base         
           operator(*)    Description
           -----------------------------------------------------------------------------------------------------------
           ib#.           use # as base, #=value of variable
           ib(##).        use the #th ordered value as base (**)
           ib(first).     use smallest value as base (the default)
           ib(last).      use largest value as base
           ib(freq).      use most frequent value as base
           ibn.           no base level
           -----------------------------------------------------------------------------------------------------------
            (*) The i may be omitted.  For instance, you may type ib2.group or b2.group.
           (**) For example, ib(#2). means to use the second value as the base.

    If you want to use group==3 as the base in a regression, you can type,

        . regress y  i.sex ib3.group

    You can also permanently set the base levels of categorical variables by using the fvset command.
二维码

扫码加我 拉你入群

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

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

2014-10-10 21:52:51
我也想了解交互项,上面这个很牛逼,但是看不明白
二维码

扫码加我 拉你入群

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

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

2014-10-12 12:30:39
就是做方差的时候anova y x v ,如果要考虑交互项就用anova y x v x#v
二维码

扫码加我 拉你入群

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

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

2015-5-13 22:49:20
dqlcsm 发表于 2014-10-12 12:30
就是做方差的时候anova y x v ,如果要考虑交互项就用anova y x v x#v
书上用的是*,原来是#
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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