楼主: 面板数据
26143 6

[其他] [求助]请教,如何求方差和协方差? [推广有奖]

  • 0关注
  • 4粉丝

博士生

59%

还不是VIP/贵宾

-

威望
0
论坛币
6578 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1080 点
帖子
72
精华
0
在线时间
536 小时
注册时间
2009-2-27
最后登录
2025-5-15

楼主
面板数据 发表于 2009-5-1 22:58:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
比如有两个序列:X和Y,如何求得方差Var(X)和协方差Cov(X,Y)?具体命令式什么呢?谢谢
二维码

扫码加我 拉你入群

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

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

关键词:协方差 VaR 如何

沙发
蓝色 发表于 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编辑过]

已有 1 人评分经验 收起 理由
remlus + 100 精彩帖子

总评分: 经验 + 100   查看全部评分

藤椅
面板数据 发表于 2009-5-2 12:25:00
能不能说得简单点,谢谢斑竹了

板凳
dyshappy 发表于 2009-5-4 06:18:00
VAR(x) :

egen vx=var(x)

Covariance :

correlate x y, covariance
https://www.dropbox.com/referrals/NTcxMjYyOTA5

报纸
younger828 发表于 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命令可以做许多东西。

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

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

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

已有 1 人评分经验 收起 理由
remlus + 100 精彩帖子

总评分: 经验 + 100   查看全部评分

7
rongrong009 发表于 2012-5-4 19:21:58
??????????????、、

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-21 12:11