全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2685 4
2016-10-09
stata创造一个二值变量(0,1)然后规定他的均值为0.7怎么做呢
二维码

扫码加我 拉你入群

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

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

全部回复
2016-10-9 08:30:57
clear
set obs 1000
gen x=(_n<=700)
su x
二维码

扫码加我 拉你入群

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

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

2016-10-11 03:21:56
夏目贵志 发表于 2016-10-9 08:30
clear
set obs 1000
gen x=(_n
确实解决了问题,不过可否问一下  "_n"  是什么意思?
二维码

扫码加我 拉你入群

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

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

2016-10-11 07:09:33
mayyyy 发表于 2016-10-11 03:21
确实解决了问题,不过可否问一下  "_n"  是什么意思?
当前观测值的序号
二维码

扫码加我 拉你入群

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

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

2016-10-11 07:27:23

遇到不懂查stata软件的help


Title

    [U] 13.4 System variables (_variables)


Description

    Expressions may also contain _variables (pronounced "underscore variables").  These are built-in
    system variables that are created and updated by Stata.  They are called _variables because their
    names all begin with the underscore (_) character.

    The _variables are

    [eqno]_b[varname] (synonym:  [eqno]_coef[varname]) contains the value (to machine precision) of the
        coefficient on varname from the most recently fitted model (such as ANOVA, regression, Cox, logit,
        probit, and multinomial logit).  See [U] 13.5 Accessing coefficients and standard errors for a
        description.

    _cons is always equal to the number 1 when used directly and refers to the intercept term when used
        indirectly, as in _b[_cons].

    _n contains the number of the current observation.


    _N contains the total number of observations in the dataset.

    _pi contains the value of pi to machine precision.

    _rc contains the value of the return code from the most recent capture command; see [P] capture.

    [eqno]_se[varname] contains the value (to machine precision) of the standard error of the coefficient
        on varname from the most recently fit model (such as ANOVA, regression, Cox, logit, probit, and
        multinomial logit).  See [U] 13.5 Accessing coefficients and standard errors for a complete
        description.

    The _n and _N variables are useful for indexing observations or generating sequences of numbers.  _n
    can act as a running counter within a by-group and _N acts as the total number within each by-group.

    _rc is useful for programmers, particularly if you want to test a command internal to a program
    without having the program terminate.


Examples

    . display _pi
    . display cos(_pi)
    . range x 0 4*_pi 100

    . sysuse auto, clear
    . generate price2 = price[_n-1]
    . regress price mpg foreign rep78
    . display _b[mpg]

    . mlogit rep78 gear_ratio displacement foreign
    . display [5]_b[foreign]

    . webuse dollhill2, clear
    . by age (smokes), sort: generate wgt=pyears[_N]


二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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