zoukankan      html  css  js  c++  java
  • stata如何建立交互项

    1. 建立新变量

    gen z=x*y

    2. 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

      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

    3. 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.
      



  • 相关阅读:
    37.1 net-- udp传输
    37 net 网络编程
    review
    java day02 记录
    36.2 线程生命周期
    36.1 线程锁
    36 Thread 多线程
    35 编码 ASCII Unicode UTF-8 ,字符串的编码、io流的编码
    34.6 Properties(k,v存储) 和io流结合使用
    今日学习总结
  • 原文地址:https://www.cnblogs.com/celine227/p/14975739.html
Copyright © 2011-2022 走看看