楼主: ermutuxia
37450 21

如何把stata数据文件里面的变量名,标签,变量取值全部导程excel格式? [推广有奖]

小桥流水人家

已卖:116份资源

学术权威

65%

还不是VIP/贵宾

-

威望
3
论坛币
313334 个
通用积分
11560.5575
学术水平
702 点
热心指数
980 点
信用等级
309 点
经验
129190 点
帖子
9288
精华
1
在线时间
4176 小时
注册时间
2009-4-27
最后登录
2024-7-23

楼主
ermutuxia 发表于 2011-6-27 13:40:54 |AI写论文
50论坛币
如何把stata数据文件里面的变量名,标签,变量取值全部导成excel格式?高手快来帮忙呀!我现在用outsheet命令和outputst命令都不能把变量标签导出来。

最佳答案

sungmoo 查看完整内容

*若采用复制粘贴思路,可采用: foreach v of var _all{ loc s=`s'+1 loc n: var l `v' g label`s'="`n'" in f } *变量组label*的首值即各变量的label。
关键词:Excel格式 STATA数据 Stata EXCEL 数据文件 EXCEL 变量 格式 Stata 数据文件

沙发
sungmoo 发表于 2011-6-27 13:40:55
expecto14 发表于 2011-6-27 22:11 输出的变量标签是log文本格式,如果要再变成excel可以使用stata或者sas读取进程序中转化为excel,或者直接进行复制粘贴。
*若采用复制粘贴思路,可采用:

foreach v of var _all{
loc s=`s'+1
loc n: var l `v'
g label`s'="`n'" in f
}

*变量组label*的首值即各变量的label。
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ermutuxia + 1 + 1 + 1 谢谢sungmoo老师!

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

藤椅
expecto14 发表于 2011-6-27 15:22:31
导出为excel文件:
xmlsave "D:\data\table.xml", doctype(excel)
之后就可以用excel打开了,然后另存一下为.xls即可。

板凳
bear1008 发表于 2011-6-27 15:26:16

报纸
expecto14 发表于 2011-6-27 15:28:37
3# bear1008

此贴是输出regression结果的,不是输出数据集的

地板
ermutuxia 发表于 2011-6-27 16:15:36
变量的标签还是没有导出 2# expecto14

7
ermutuxia 发表于 2011-6-27 16:22:14
里面的东西不是我想找的,谢谢! 3# bear1008

8
expecto14 发表于 2011-6-27 22:11:42
5# ermutuxia
变量标签稍微有点麻烦,步骤如下:
1.打开dta数据集
2.运行svvarlbl的ado文件(下载地址:http://ideas.repec.org/c/boc/bocode/s400103.html)。
复制代码到stata的do-file editor里面,保存为D:\data\outlabel.do,然后在stata里面输入:do D:\data\outlabel.do

前两步也可以直接search svvarlbl, all,然后安装

3.输入:svvarlbl using varlabel.log

输出的变量标签是log文本格式,如果要再变成excel可以使用stata或者sas读取进程序中转化为excel,或者直接进行复制粘贴。
已有 4 人评分学术水平 热心指数 信用等级 收起 理由
奇犽dsp + 1 精彩帖子
syy103 + 1 + 1 + 1 观点有启发
freeolina + 1 + 1 精彩帖子
xgdl2010 + 1 + 1 + 1 精彩帖子

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

9
expecto14 发表于 2011-6-27 22:13:05
ado文件的代码如下,直接复制粘贴到do-file editor里面即可:


*! 1.0.0 DEMW 29 NOV 1999
* This program outputs the variable labels
* And can save the output to a do-file which you can
* then use to label other variables in another dataset
* Correct syntax => svvarlbl varlist [using filename] [, replace]
program define svvarlbl
        version 6
        syntax [varlist] [using/] [, replace]
        tokenize `varlist'
        if "`replace'" != "" { local using `"`using', replace"' }

        if `"`using'"' != `""' {
                local logfile : log
                local logfile = lower("`logfile'")
                if "`logfile'" != "" {
                        di in bl /*
                        */ "Note: log `logfile' suspended for -svvarlbl-"
                        log close }

                cap log using `using'
                       if _rc{
                        local rc = _rc
                        local pwd:pwd
                        local pwd = lower("`pwd'")
                        if "`logfile'" != "" {
                                log using `logfile', append
                                di in bl /*
                                */"Note: log `logfile' resumed after error in
-svvarlbl-"
                        }
                dis in red "File `pwd'\\`using' already exists"
                exit `rc'                
                }
        }

        local i = 1
        while "``i''" != "" {
                loc vlbl : variable label ``i''
                dis `" cap label variable ``i'' "`vlbl'""'
                local i = `i' + 1
        }

        if `"`using'"' != `""' { log close }

        if "`logfile'" != "" {
                log using `logfile', append
                di in bl _n "Note: log `logfile' resumed after -svvarlbl-"
        }
end

(来源:http://fmwww.bc.edu/repec/bocode/s/svvarlbl.ado

10
expecto14 发表于 2011-6-28 09:49:45
还有一种更简单的方法:fsum
如果变量不多,可以用fsum的label option,具体操作如下:

search fsum, all;选fsum然后安装
fsum, stats(n) label
选中result中的变量和标签,右键Copy Table,然后在Excel中粘贴即可
已有 8 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
7945_1573892162 + 1 + 1 + 1 精彩帖子
award + 5 + 5 + 5 + 1 精彩帖子
海底鱼huo + 1 + 1 + 1 + 1 精彩帖子
heyskytree + 1 + 1 + 1 精彩帖子
1023715119 + 4 + 4 + 4 精彩帖子
tbic2012 + 1 + 1 + 1 精彩帖子
celesta + 4 精彩帖子
ermutuxia + 1 + 1 + 1 谢谢你的热心帮助!

总评分: 论坛币 + 6  学术水平 + 18  热心指数 + 14  信用等级 + 10   查看全部评分

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

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