全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
7332 7
2015-05-18
xfill貌似不是官方命定,所以不同通过ssc来安装,在stata命定窗口中输入
net from http://www.sealedenvelope.com/ 然后找到xfill进行安装。
真的很方便,谁用谁知道!

帖子来源:http://www.sealedenvelope.com/stata/xfill/
xfill
A Stata program to fill in values within clusters

By Tony Brady

If you haven't already done so, you may find it useful to read the article on xtabbecause it discusses what we mean by longitudinal data and static variables.

xfill is a utility that 'fills in' static variables. It replaces missing values in a cluster with the unique non-missing value within that cluster. It's easiest to see what's meant by this with an example.

Example

To follow this example in Stata type:

use http://www.sealedenvelope.com/stata/long.dta

in the Stata command window.

Look at the variable sex in our example dataset (long.dta):

sex is a static variable since it does not change within cluster (in this case the cluster is the patient). As is commonly the case with static variables, it has been recorded only in the first record within cluster. To fill in the missing values we type

. xfill sex, i(idnum)

So now our data looks like this:

Why would we want to do this? The reason is that it makes the output from other longitudinal commands easier to interpret when performed in subgroups. For instance, look at the results of xcount within by groups before we filled in sex:

This suggests that we have 14 males, 1 female and 14 patients whose gender is unknown. In fact we know the sex of all 15 patients in this dataset. The 14 phantom patients of unknown gender are being produced because patients are recorded as either male or female in the 1st record and as unknown sex in 2nd and subsequent records. One patient only has a 1st record and no subsequent records which is why the number of patients of unknown gender isn't 15.

The simple solution to this problem is to replace the missing values with their true values, in this case the patient's sex:

Now the 14 patients of apparently unknown gender are eliminated from our results. Similar problems occur when summarising static variables using if andin clauses. xfill prevents such confusion arising.




二维码

扫码加我 拉你入群

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

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

全部回复
2015-5-18 23:17:26
复制代码

文中举的例子,这样也可以啊~
那么xfill还有其余的功能么?
二维码

扫码加我 拉你入群

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

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

2015-5-18 23:32:28
luckykong 发表于 2015-5-18 23:17
文中举的例子,这样也可以啊~
那么xfill还有其余的功能么?
厉害,效果应该是一样的,我暂时只用到这个功能
二维码

扫码加我 拉你入群

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

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

2015-5-19 14:51:54
看看也许以后能用
二维码

扫码加我 拉你入群

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

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

2019-12-11 16:16:16
luckykong 发表于 2015-5-18 23:17
文中举的例子,这样也可以啊~
那么xfill还有其余的功能么?
这个写法我好像报错呢
二维码

扫码加我 拉你入群

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

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

2021-4-21 11:21:49
同学,你好呀,因为毕业论文的程序需要用到xfill这个命令,你可以教我一下如何安装这个命令吗,因为我试了你在论坛上说的方法,目前发觉不行,希望同学可以帮帮忙,谢谢
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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