全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
26004 6
2009-05-01
比如有两个序列:X和Y,如何求得方差Var(X)和协方差Cov(X,Y)?具体命令式什么呢?谢谢
二维码

扫码加我 拉你入群

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

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

全部回复
2009-5-2 08:15:00

help for correlate, pwcorr                                                      manual:  [R] correlate   
                                                                               dialogs:  correlate  pwcorr
----------------------------------------------------------------------------------------------------------

Correlations (covariances) of variables or estimators

        correlate [varlist] [weight] [if exp] [in range] [, means noformat covariance _coef wrap ]

        pwcorr    [varlist] [weight] [if exp] [in range] [, obs sig print(#) star(#) bonferroni sidak ]


    by ... : may be used with the above commands; see help by.

    aweights and fweights are allowed; see help weights.

    The varlist following correlate may contain time-series operators; see help varlist.


Description

    correlate without the _coef option displays the correlation or covariance matrix for varlist or, if
    varlist is not specified, for all variables in the data.  Observations are excluded from the
    calculation due to missing values on a casewise basis.

    pwcorr displays all the pairwise correlation coefficients between the variables in varlist or, if
    varlist is not specified, all the variables in the dataset.

    correlate with the _coef option displays the correlation or covariance matrix of the coefficients
    from the most recently fitted model.  varlist is not specified in this case.


Options used with correlate

    means causes summary statistics (means, standard deviations, minimums, and maximums) to be displayed
        along with the matrix.

    noformat displays the summary statistic requested by the means option in g format regardless of the
        display formats associated with the variables.

    covariance displays the covariances rather than the correlation coefficients.

    _coef displays the correlations (or covariances if covariance is also specified) between the
        coefficients of the most recently fitted model.

    wrap requests that no action be taken on wide matrices to make them readable.  It is unlikely that
        you will ever want to specify this option; it prevents Stata from breaking wide matrices into
        pieces to enhance readability.


Options used with pwcorr

    obs adds a line to each row of the matrix reporting the number of observations used in calculating
        the correlation coefficient.

    sig adds a line to each row of the matrix reporting the significance level of each correlation
        coefficient.

    print(#) specifies the significance level of correlation coefficients to be printed.  Coefficients
        with larger significance levels are left blank.  print(10) or print(.1) would list only
        coefficients significant at the 10% level or better.

    star(#) specifies the significance level of coefficients to be starred.  star(5) or star(.05) would
        star all coefficients significant at the 5% level or better.

    bonferroni makes the Bonferroni adjustment to calculated significance levels.  This affects printed
        significance levels and the print() and star() options.  "pwcorr, print(.05) bonferroni" prints
        coefficients with Bonferroni-adjusted significance levels of .05 or less.

    sidak makes the Sidak adjustment to calculated significance levels.  This affects printed
        significance levels and the print() and star() options.  "pwcorr, print(.05) sidak" prints
        coefficients with Sidak-adjusted significance levels of .05 or less.


Examples

    . correlate
    . correlate mrgrate dvcrate medage
    . correlate mrgrate dvcrate medage, covariance
    . correlate mrgrate dvcrate medage [aw=pop], covariance


    . regress y x1 x2                                    (substitute any estimation command for regress) 
    . correlate, _coef
    . correlate, _coef cov


    . pwcorr
    . pwcorr price weight mpg displ
    . pwcorr price weight mpg displ, sig obs
    . pwcorr price weight mpg displ, sig bon
    . pwcorr price weight mpg displ, star(.05)
    . pwcorr price weight mpg displ, star(.05) bon
    . pwcorr price weight mpg displ, print(.05) star(.01) bon


Also see

    Manual:  [R] correlate

    Online:  help for impute, pcorr, spearman, summarize, vce

[此贴子已经被作者于2009-5-2 8:16:48编辑过]

二维码

扫码加我 拉你入群

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

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

2009-5-2 12:25:00
能不能说得简单点,谢谢斑竹了
二维码

扫码加我 拉你入群

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

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

2009-5-4 06:18:00
VAR(x) :

egen vx=var(x)

Covariance :

correlate x y, covariance
二维码

扫码加我 拉你入群

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

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

2009-5-4 19:23:00

在matlab里用 a=var(x)可求得序列x的方差为a, 用B=cov(X,Y)可得X与Y的协方差矩阵B 

二维码

扫码加我 拉你入群

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

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

2009-5-4 21:22:00
以下是引用面板数据在2009-5-2 12:25:00的发言:
能不能说得简单点,谢谢斑竹了

我是告诉你corr命令可以做许多东西。

你不能为了求方差,会了一个

下次做别的就不知道用什么了啊。

你看看帮助,这个命名的选项,需要求什么,就加什么选项。

二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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