全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
3763 15
2016-08-27
求助大家:请教个问题,已经用xi i.industry 生成了一个行业虚拟变量,想用xi i.city 再生成一个区域虚拟变量,但是一旦运行xi i.city,原来xi i.industry 生成的的那些虚拟变量没有了,请教是怎么回事?应该怎么修改?谢谢~
二维码

扫码加我 拉你入群

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

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

全部回复
2016-8-27 15:34:18
fuzixi1125 发表于 2016-8-27 11:06
求助大家:请教个问题,已经用xi i.industry 生成了一个行业虚拟变量,想用xi i.city 再生成一个区域虚拟变 ...
因为生成的变量相同,后生成的数据会覆盖之前的内容
二维码

扫码加我 拉你入群

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

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

2016-8-27 15:42:40
guopeng8899@126 发表于 2016-8-27 15:34
因为生成的变量相同,后生成的数据会覆盖之前的内容
不是很明白,前面生成的是city,另一个是industry,怎么会相同呢?能解释一下吗?本人刚入门不是很懂stata。。。谢谢。。。。
二维码

扫码加我 拉你入群

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

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

2016-8-27 15:47:38
你不会是先
复制代码
然后
复制代码
吧?的确,我试了一下,如楼上所说,后面会取代前面!要产生两组虚拟变量,可试试
复制代码
二维码

扫码加我 拉你入群

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

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

2016-8-27 15:49:22
但若是要跑回归,请用:
复制代码
二维码

扫码加我 拉你入群

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

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

2016-8-27 18:13:48
用什么命令就看那个命令的帮助和解释。

Title
    [R] xi -- Interaction expansion
Syntax
        xi [, prefix(string) noomit] term(s)
        xi [, prefix(string) noomit] : any_stata_command varlist_with_terms ...

    where a term has the form
        i.varname                     or       I.varname
        i.varname1*i.varname2                  I.varname1*I.varname2
        i.varname1*varname3                    I.varname1*varname3
        i.varname1|varname3                    I.varname1|varname3

    varname, varname1, and varname2 denote numeric or string categorical variables.  varname3
    denotes a continuous, numeric variable.

Menu
    Data > Create or change data > Other variable-creation commands > Interaction expansion

    +-----------------------------------------------------------------+
    | Most commands in Stata now allow factor variables; see          |
    | fvvarlist. To determine if a command allows factor variables,   |
    | see the information printed below the options table for the     |
    | command.  If the command allows factor variables, it will say   |
    | something like "indepvars may contain factor variables."        |
    |                                                                 |
    | We recommend that you use factor variables instead of xi if a   |
    | command allows factor variables.                                |
    |                                                                 |
    | We include [R] xi in our documentation so that readers can      |
    | consult it when using a Stata command that does not allow       |
    | factor variables.                                               |
    +-----------------------------------------------------------------+

Description
    xi expands terms containing categorical variables into indicator (also called dummy)
    variable sets by creating new variables and, in the second syntax (xi: any_stata_command),
    executes the specified command with the expanded terms.  The dummy variables created are
        i.varname               creates dummies for categorical variable varname
        i.varname1*i.varname2   creates dummies for categorical variables varname1 and varname2:
                               all interactions and main effects
        i.varname1*varname3     creates dummies for categorical variable varname1 and continuous
                                variable varname3: all interactions and main effects
        i.varname1|varname3     creates dummies for categorical variable varname1 and continuous
                                variable varname3: all interactions and main effect of varname3,
                                but no main effect of varname1
Options
    prefix(string) allows you to choose a prefix other than _I for the newly created interaction  variables.  The prefix cannot be longer than four characters.  By default, xi will create interaction variables starting with _I.  When you use xi, it drops all previously  created interaction variables starting with the prefix specified in the prefix(string) option or with _I by default.  Therefore, if you want to keep the variables with a certain prefix, specify a different prefix in the prefix(string) option.



    noomit prevents xi from omitting groups.  This option provides a way to generate an
        indicator variable for every category having one or more variables, which is useful when
        combined with the noconstant option of an estimation command.


二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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