楼主: luxun1712
72405 18

[回归分析求助] Stata12做回归如何建立交互项 [推广有奖]

  • 0关注
  • 1粉丝

已卖:28份资源

讲师

10%

还不是VIP/贵宾

-

威望
0
论坛币
306 个
通用积分
0.0016
学术水平
2 点
热心指数
1 点
信用等级
0 点
经验
298 点
帖子
154
精华
0
在线时间
556 小时
注册时间
2009-3-15
最后登录
2016-4-16

楼主
luxun1712 发表于 2013-10-14 18:19:08 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
比如说 X、Y两个自变量,若要在stata12中进行回归时建立交互项,那么交互项该如何表示
二维码

扫码加我 拉你入群

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

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

关键词:stata12 Stata 如何建立 tata 交互项 自变量 如何

沙发
cactus90 学生认证  发表于 2013-10-14 18:27:14
建立新变量

gen z=x*y
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
日新少年 + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

We progress hand in hand, down to earth while aiming high, create every single miracle with a drip.[img]http:/

藤椅
蓝色 发表于 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.
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
造化5 + 1 + 1 + 1 观点有启发
Sunknownay + 100 + 10 + 1 + 1 + 1 热心帮助其他会员

总评分: 经验 + 100  论坛币 + 10  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

板凳
240384yh 发表于 2014-10-10 21:52:51
我也想了解交互项,上面这个很牛逼,但是看不明白

报纸
dqlcsm 发表于 2014-10-12 12:30:39
就是做方差的时候anova y x v ,如果要考虑交互项就用anova y x v x#v

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

7
豔豔的空城 发表于 2015-5-14 15:17:52
明白了,十分感谢

8
connie82981 发表于 2016-2-29 17:20:36
楼主您好,看了您上面的回复,试验了下,果然交互项的命令在stata12 版本与11之前的版本不一样,非常感谢。
但现在又发现一个不一样的,就是协方差分析,命令应该也不一样,我输入命令如下:
anova wage children married children * married education, continuous(education)
运行不出来。
请教

9
connie82981 发表于 2016-2-29 17:21:19
dqlcsm 发表于 2014-10-12 12:30
就是做方差的时候anova y x v ,如果要考虑交互项就用anova y x v x#v
不好意思回复错了。
楼主您好,看了您上面的回复,试验了下,果然交互项的命令在stata12 版本与11之前的版本不一样,非常感谢。
但现在又发现一个不一样的,就是协方差分析,命令应该也不一样,我输入命令如下:
anova wage children married children * married education, continuous(education)
运行不出来。
请教

10
yangyangjun 发表于 2016-3-19 14:08:25
connie82981 发表于 2016-2-29 17:21
不好意思回复错了。
楼主您好,看了您上面的回复,试验了下,果然交互项的命令在stata12 版本与11之前的 ...
我觉得做交互项最好的方式还是先乘起来,再进入模型

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-1 07:10