楼主: dandan_9075
23304 11

[其他] sata做回归的时候怎么设置参照组 [推广有奖]

  • 3关注
  • 2粉丝

硕士生

52%

还不是VIP/贵宾

-

威望
0
论坛币
21 个
通用积分
2.5503
学术水平
1 点
热心指数
4 点
信用等级
1 点
经验
1215 点
帖子
134
精华
0
在线时间
110 小时
注册时间
2012-3-12
最后登录
2024-1-2

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
用stata做回归的时候,自变量有多分类变量age,我先将它用 tab  age,gen(yfec)生成五个哑变量如下所示,

age

yfec1

yfec2

yfec3

yfec4

yfec5

1

1

0

0

0

0

2

0

1

0

0

0

3

0

0

1

0

0

4

0

0

0

1

0

5

0

0

0

0

1


,但是在拟合模型的时候是默认将age=1这一组作为参照组的,现在我想在拟合模型的时候让age=3作为参照组,我该怎么办呢?(说明一下哈,我的数据比较多,所以手工改的话工作量大,而且不能保证质量),请教高手怎么实现呢?
二维码

扫码加我 拉你入群

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

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

关键词:SATA SAT Stata tata 请教高手 工作量 自变量 而且 模型 手工

本帖被以下文库推荐

沙发
Mertesacker 发表于 2012-8-15 15:07:09 |只看作者 |坛友微信交流群
我都是用土办法   复制到excel里面   调换一下

命令肯定可以做到,但我没做过哈
已有 1 人评分热心指数 收起 理由
逐梦的太阳 + 5 热心帮助其他会员

总评分: 热心指数 + 5   查看全部评分

使用道具

藤椅
蓝色 发表于 2012-8-15 15:50:53 |只看作者 |坛友微信交流群
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.


Selecting levels

    You can select a range of levels -- a range of virtual variables -- by using the i(numlist). operator.

         Examples          Description
         --------------------------------------------------------------------------------------------------
         i2.cat            a single indicator for cat==2

         2.cat             same as i2.cat

         i(2 3 4).cat      three indicators, cat==2, cat==3, and cat==4;
                             same as i2.cat i3.cat i4.cat

         i(2/4).cat        same as i(2 3 4).cat

         2.cat#1.sex       a single indicator that is 1 when cat==2 and sex==1, and is 0 otherwise

         i2.cat#i1.sex     same as 2.cat#1.sex
         --------------------------------------------------------------------------------------------------


Applying operators to a group of variables

    Factor-variable operators may be applied to groups of variables by using parentheses.

    In the examples that follow, variables group, sex, arm, and cat are categorical, and variables age, wt,
    and bp are continuous:

         Examples                  Expansion
         --------------------------------------------------------------------------------------------------
         i.(group sex arm)         i.group i.sex i.arm

         group#(sex arm cat)       group#sex group#arm group#cat

         group##(sex arm cat)      i.group i.sex i.arm i.cat group#sex group#arm group#cat

         group#(c.age c.wt c.bp)   i.group group#c.age group#c.wt group#c.bp

         group#c.(age wt bp)       same as group#(c.age c.wt c.bp)
         --------------------------------------------------------------------------------------------------
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
wshzh + 1 + 1 + 1 热心帮助其他会员
逐梦的太阳 + 5 + 5 + 5 热心帮助其他会员

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

使用道具

板凳
老树皮 发表于 2012-8-16 06:43:56 |只看作者 |坛友微信交流群
char age[omit] 3
xi: reg y i.age
已有 1 人评分热心指数 收起 理由
逐梦的太阳 + 5 热心帮助其他会员

总评分: 热心指数 + 5   查看全部评分

使用道具

报纸
gslzwjw 发表于 2016-4-19 21:23:05 |只看作者 |坛友微信交流群
蓝色 发表于 2012-8-15 15:50
Title

     11.4.3 Factor variables
赞!这回清楚如何设置哑变量并设置参照组了

使用道具

地板
frederick2012 发表于 2018-3-12 21:59:16 |只看作者 |坛友微信交流群
收藏收藏

使用道具

7
w530366897 在职认证  发表于 2018-7-10 16:18:30 |只看作者 |坛友微信交流群
我想问一下,为什么在前面加i.并没有什么变化呢?是用这个有前提条件吗?

使用道具

8
hyhxx827 发表于 2018-11-9 15:26:55 |只看作者 |坛友微信交流群
蓝色 发表于 2012-8-15 15:50
Title

     11.4.3 Factor variables
感谢,有用!

使用道具

9
bdim 发表于 2019-1-21 19:09:48 |只看作者 |坛友微信交流群
谢谢,收藏了再说

使用道具

10
tzz925931604 学生认证  发表于 2020-7-16 12:58:09 |只看作者 |坛友微信交流群
谢谢! help fvvarlist##bases

使用道具

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

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 02:20