楼主: 天涯在何方
1965 9

排除自身的平均命令怎么写 [推广有奖]

  • 0关注
  • 6粉丝

VIP

康奈尔之旅

副教授

75%

还不是VIP/贵宾

-

威望
0
论坛币
518 个
通用积分
51.5343
学术水平
8 点
热心指数
14 点
信用等级
10 点
经验
250 点
帖子
341
精华
0
在线时间
1581 小时
注册时间
2005-8-9
最后登录
2024-3-4

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
最近看一篇文章,要计算排除了本家庭的信任度之外的其他样本家庭的平均信任度,求教这个命令是怎么写的?
数据简介: COUN省县代码  VILL  村庄代码 HOUS    住户代码   trust信任度
一个家庭所在村庄层面的平均信任度:by  COUN VILL: egen trustmean=mean(trust),可是如何计算排除此家庭之外其他样本家庭的平均信任度呢?先谢谢了。
二维码

扫码加我 拉你入群

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

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

关键词:trust tmean mean egen 信任度 命令 排除

数据.rar

13.23 KB

本附件包括:

  • 复件 third.dta

We are what we eat, you are what you think.
沙发
jzhyue 发表于 2010-9-14 11:22:37 |只看作者 |坛友微信交流群
1# 天涯在何方
*看是否合要求
bys COUN VILL :egen t=total(trust)
bys COUN VILL :gen tmean=(t-trust)/(_N-1)
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
inscar + 1 + 1 + 1 观点有启发

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

使用道具

藤椅
天涯在何方 发表于 2010-9-14 11:36:55 |只看作者 |坛友微信交流群
jzhyue 发表于 2010-9-14 11:22
1# 天涯在何方
*看是否合要求
bys COUN VILL :egen t=total(trust)
bys COUN VILL :gen tmean=(t-trust)/(_N-1)
知道这个思想,就是不知道命令怎么写,呵呵,多谢兄台指点!
We are what we eat, you are what you think.

使用道具

板凳
ctx5518 发表于 2010-9-14 11:41:59 |只看作者 |坛友微信交流群
levelsof HOUS, local(household)

foreach x of local household {
        gen trust2= trust
        replace trust2 = . if HOUS == `x'
        by COUN VILL: egen trustmean`x' = mean(trust2)
        drop trust2
}

使用道具

报纸
天涯在何方 发表于 2010-9-14 12:06:59 |只看作者 |坛友微信交流群
ctx5518 发表于 2010-9-14 11:41
levelsof HOUS, local(household)

foreach x of local household {
        gen trust2= trust
        replace trust2 = . if HOUS == `x'
        by COUN VILL: egen trustmean`x' = mean(trust2)
        drop trust2
}
佩服佩服。也感谢jzhyue的解答,我本来和您是一样的想法,但这位兄台的命令也很有道理。特奉上统计描述,以供大家比较。
   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
  trustmean1 |      9195    3.513549    .8065215          1          5
       tmean |      9194    3.518055    .8044878          1          5
       trust |      9194     3.51849    1.323353          1          5
We are what we eat, you are what you think.

使用道具

地板
jzhyue 发表于 2010-9-14 15:48:28 |只看作者 |坛友微信交流群
天涯在何方 发表于 2010-9-14 12:06
ctx5518 发表于 2010-9-14 11:41
levelsof HOUS, local(household)

foreach x of local household {
        gen trust2= trust
        replace trust2 = . if HOUS == `x'
        by COUN VILL: egen trustmean`x' = mean(trust2)
        drop trust2
}
佩服佩服。也感谢jzhyue的解答,我本来和您是一样的想法,但这位兄台的命令也很有道理。特奉上统计描述,以供大家比较。
   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
  trustmean1 |      9195    3.513549    .8065215          1          5
       tmean |      9194    3.518055    .8044878          1          5
       trust |      9194     3.51849    1.323353          1          5
*按照ctx5518的思路
levelsof HOUS, local(household)
gen ttmean=.
foreach x of local household {
        gen trust2= trust
        replace trust2 = . if HOUS == `x'
        by COUN VILL: egen trustmean`x' = mean(trust2)
        drop trust2
  replace ttmean=trustmean`x' if HOUS == `x'
}
drop trustmean*

使用道具

7
天涯在何方 发表于 2010-9-14 16:14:19 |只看作者 |坛友微信交流群
jzhyue 发表于 2010-9-14 15:48
天涯在何方 发表于 2010-9-14 12:06
ctx5518 发表于 2010-9-14 11:41
levelsof HOUS, local(household)

foreach x of local household {
        gen trust2= trust
        replace trust2 = . if HOUS == `x'
        by COUN VILL: egen trustmean`x' = mean(trust2)
        drop trust2
}
佩服佩服。也感谢jzhyue的解答,我本来和您是一样的想法,但这位兄台的命令也很有道理。特奉上统计描述,以供大家比较,从样本数目来看,9194是和原样本一致的。
   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
  trustmean1 |      9195    3.513549    .8065215          1          5
       tmean |      9194    3.518055    .8044878          1          5
       trust |      9194     3.51849    1.323353          1          5
*按照ctx5518的思路
levelsof HOUS, local(household)
gen ttmean=.
foreach x of local household {
        gen trust2= trust
        replace trust2 = . if HOUS == `x'
        by COUN VILL: egen trustmean`x' = mean(trust2)
        drop trust2
  replace ttmean=trustmean`x' if HOUS == `x'
}
drop trustmean*
谢谢,这回我把这个命令输入,得到第一种思路和第二种思路的描述统计,他们虽然不一致,但是很接近了。
    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      ttmean |      9195    3.518543    .8046014          1          5
       tmean |      9194    3.518055    .8044878          1          5
We are what we eat, you are what you think.

使用道具

8
jzhyue 发表于 2010-9-14 16:50:27 |只看作者 |坛友微信交流群
*问题的关键是trust是否有缺失值,而你的数据就有一个:下面排除缺失值(同6楼)
bys COUN VILL :egen t=total(trust)
bys COUN VILL :egen tn=count(trust)
gen tmean=(t-trust)/(tn-1)
sum if trust~=.
*如果将缺失值作为观察值之一,下面比较合理(因为没有删除缺失值,而上面的方法与6楼的方法都不考虑缺失值)
bys COUN VILL :egen t=total(trust)
bys COUN VILL :gen tmean=(t-trust)/(_N-1)

使用道具

9
jzhyue 发表于 2010-9-14 17:06:59 |只看作者 |坛友微信交流群
天涯在何方 发表于 2010-9-14 16:14
jzhyue 发表于 2010-9-14 15:48
天涯在何方 发表于 2010-9-14 12:06
ctx5518 发表于 2010-9-14 11:41

谢谢,这回我把这个命令输入,得到第一种思路和第二种思路的描述统计,他们虽然不一致,但是很接近了。
    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      ttmean |      9195    3.518543    .8046014          1          5
       tmean |      9194    3.518055    .8044878          1          5
我想应这样统计:
sum if trust~=.

VariableObsMeanStd. Dev.MinMax
trust91943.518491.32335315
ttmean91943.51849.804629515
tmean91943.51849.804629515

使用道具

10
天涯在何方 发表于 2010-9-14 17:27:03 |只看作者 |坛友微信交流群
jzhyue 发表于 2010-9-14 16:50
*问题的关键是trust是否有缺失值,而你的数据就有一个:下面排除缺失值(同6楼)
bys COUN VILL :egen t=total(trust)
bys COUN VILL :egen tn=count(trust)
gen tmean=(t-trust)/(tn-1)
sum if trust~=.
*如果将缺失值作为观察值之一,下面比较合理(因为没有删除缺失值,而上面的方法与6楼的方法都不考虑缺失值)
bys COUN VILL :egen t=total(trust)
bys COUN VILL :gen tmean=(t-trust)/(_N-1)
这回这个问题看的透彻多了,多谢兄台指点!
We are what we eat, you are what you think.

使用道具

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

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

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

GMT+8, 2024-4-30 18:03