全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
6188 10
2013-01-21
国际货币基金组织(IMF)世界经济展望(World Economic Outlook [WEO])
2012年10月份的数据库
数据源:
http://www.imf.org/external/pubs/ft/weo/2012/02/weodata/download.aspx
引用请注明出处:October 2012 WEO Database
附件
WEOupdate.zip
大小:(4.32 MB)

只需: 2 个论坛币  马上下载

本附件包括:

  • WEOOct2012alla.xls
  • weom.csv
  • weooct2012.dta
  • WEOOct2012all.xls

(已更新,原先的group()用的是var应该用varlab)内含整理好的*.dta-file
(参照sungmoo的标签解法,为便于交流,do-file源码贴到尾部,大家看看有什么更快捷的办法)
以下是变量描述(Stata限定变量标签不得超出80个字符):
variable namevariable label
countryCountry
isoISO
estyrEstimates Start After
year
BCA_NGDPDcurrent account balance;percent of gdp;
BCAcurrent account balance;u.s. dollars;billions
LEemployment;persons;millions
GGXWDGgeneral government gross debt;national currency;billions
GGXWDG_NGDPgeneral government gross debt;percent of gdp;
GGXWDNgeneral government net debt;national currency;billions
GGXWDN_NGDPgeneral government net debt;percent of gdp;
GGXCNLgeneral government net lending/borrowing;national currency;billions
GGXCNL_NGDPgeneral government net lending/borrowing;percent of gdp;
GGXONLBgeneral government primary net lending/borrowing;national
currency;billions
GGXONLB_NGDPgeneral government primary net lending/borrowing;percent of gdp;
GGRgeneral government revenue;national currency;billions
GGR_NGDPgeneral government revenue;percent of gdp;
GGSBgeneral government structural balance;national currency;billions
GGSB_NPGDPgeneral government structural balance;percent of potential gdp;
GGXgeneral government total expenditure;national currency;billions
GGX_NGDPgeneral government total expenditure;percent of gdp;
PPPPCgross domestic product based on purchasing-power-parity (ppp) per capita
gdp;cur
PPPSHgross domestic product based on purchasing-power-parity (ppp) share of
world tot
PPPGDPgross domestic product based on purchasing-power-parity (ppp) valuation
of count
NGDP_FYgross domestic product corresponding to fiscal year, current
prices;national cur
NGDPRPCgross domestic product per capita, constant prices;national
currency;units
NGDPPCgross domestic product per capita, current prices;national currency;units
NGDPDPCgross domestic product per capita, current prices;u.s. dollars;units
NGDP_Rgross domestic product, constant prices;national currency;billions
NGDP_RPCHgross domestic product, constant prices;percent change;
NGDPgross domestic product, current prices;national currency;billions
NGDPDgross domestic product, current prices;u.s. dollars;billions
NGDP_Dgross domestic product, deflator;index;
NGSD_NGDPgross national savings;percent of gdp;
PPPEXimplied ppp conversion rate;national currency per current international
dollar;
PCPIinflation, average consumer prices;index;
PCPIPCHinflation, average consumer prices;percent change;
PCPIEinflation, end of period consumer prices;index;
PCPIEPCHinflation, end of period consumer prices;percent change;
NGAP_NPGDPoutput gap in percent of potential gdp;percent of potential gdp;
LPpopulation;persons;millions
FLIBOR6six-month london interbank offered rate (libor);percent;
NID_NGDPtotal investment;percent of gdp;
LURunemployment rate;percent of total labor force;
TXGOvalue of oil exports;u.s. dollars;billions
TMGOvalue of oil imports;u.s. dollars;billions
TX_RPCHvolume of exports of goods and services;percent change;
TXG_RPCHvolume of exports of goods;percent change;
TM_RPCHvolume of imports of goods and services;percent change;
TMG_RPCHvolume of imports of goods;percent change;

开源数据,一起分享
*weom.csv消掉了源数据库里的n/a和--insheet using weom.csv, names clearinsheet using weom.csv, names clear
foreach i of numlist 10/47 {
        local j=`i'+1970
        rename v`i' y`j'
}
save weo,replace
rename weosubjectcode varcode
rename subjectdescri~r var
rename weocountrycode countrycode
rename estimatesstar~r estyr
egen varm=concat(var units scale), p(;)
replace varm=strlower(varm)
drop var countrycode subjectnotes units scale countryseriesspecificnotes
order country iso varcode varm estyr
rename varcode var
rename varm varlab
outsheet using work.csv,names comma replace
save weom,replace
reshape long y,i(country iso var varlab estyr) j(year)
save work,replace
use work,clear
sort iso varlab
keep if iso=="AFG"
keep var
duplicates drop
gen n=_n
gen N=_N
reshape wide var, i(N) j(n)
drop N
*字串型变量上限为244字符[只能存入前32个变量名称(共46个)],所以拆成两断(长度分别为179和146)
*用空格做断点,为后面token做铺垫
*(试过别的不成,比如分号,逗号什么的,token会把这些符号存在positional local macro里)
egen name1=concat(var1-var23),punct(" ")
egen name2=concat(var24-var46),punct(" ")
keep name*
local x=name1
*断点识别符为空格
token `x',parse(" ")
* 因为后面标签也要用到positional local macro,所以这里变量名称要转存在其他local macro名下,
* 此处用nm1-nm46,分成两次(1-23和24-46),因为之前由于字串过长拆过。
forvalues i=1/23{
        local nm`i' ``i''
}
local x=name2
*断点识别符为空格
token `x',parse(" ")
forvalues i=1/23{
        local j=`i'+23
        local nm`j' ``i''
}
use work,clear
*加标签
egen v=group(varlab)
levelsof varlab,l(v)
token `"`v'"',p("' `")
drop varlab var
reshape wide y,i(country iso year estyr) j(v)
forv i=1/46{
        la var y`i' `"``i''"'
}
*标签加完
save new,replace

use new,clear
*重命名
forvalues i=1/46{
        rename y`i' `nm`i''
}
save weooct2012,replace
以上办法可实现系统自动完成标签+命名(无需在rename或renvars中手动贴入变量名称)
经测,可行,不知有没有更好的办法,求解。



附件列表

WEO.zip

大小:2.81 MB

 马上下载

请勿下载

本附件包括:

  • WEOOct2012alla.xls
  • weooct2012.dta
  • WEOOct2012all.xls

二维码

扫码加我 拉你入群

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

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

全部回复
2013-1-21 09:36:48
好资料,多谢楼主
二维码

扫码加我 拉你入群

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

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

2013-1-21 09:38:41
22691000 发表于 2013-1-21 09:36
好资料,多谢楼主
多谢支持
二维码

扫码加我 拉你入群

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

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

2013-1-21 16:47:57
请问楼主:
      egen varm=concat(var units scale), p(;)
     token `"`v'"',p("' `")

请问楼主:红色的函数和命令是何含义?期待您的回复



二维码

扫码加我 拉你入群

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

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

2013-1-21 16:53:49
另外,批量改名字我常用renvars命令,而您用的是rename ()(),我的stata11.2并不能执行。您用rename能批量改变量名吗?
二维码

扫码加我 拉你入群

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

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

2013-1-22 04:37:01
sewind_tj 发表于 2013-1-21 16:47
请问楼主:
      egen varm=concat(var units scale), p(;)
     token `"`v'"',p("' `")
concat 即concatenate,连接的意思,该函数属egen系列,
就是说,如果想详细了解的话,可以help concat,然后egen -> ctrl+f -> concat,即可找到相应的help file
即 concat(varlist) [, format(%fmt) decode maxlength(#) punct(pchars)]            may not be combined with by.  It concatenates varlist to produce a string variable.  Values of string variables are unchanged.  Values of numeric variables are
            converted to string, as is, or are converted using a numeric format under the format(%fmt) option or decoded under the decode option, in which case maxlength() may
            also be used to control the maximum label length used.  By default, variables are added end to end: punct(pchars) may be used to specify punctuation, such as a
            space, punct(" "), or a comma, punct(,).
功能就是合并(连接)几个变量,
比如有变量var, vardescription, units,scale
var

vardescription

units

scale
NGDP_D

Gross domestic  product, current prices

national currency

billions

concat的option里有个 punct(pchars), 这个的作用就是设定连接几个变量所用的连接符,我用的是分号;

所以其结果就是
varm的在观测值上的值为Gross domestic product, current prices;national currency;billions
之所以要连接,是因为每个国家的变量描述vardescription里有重复的,而他们之间的区别在于度量单位units不同,或是规模/级别scale不同,如果用unique函数显示var中的不同值,有46个,但是vardescription 只有 30多个,
那么在重新给变量加标签的时候,就不足了,但是通过concat,合并vardescription,units,scale后,新生成的(用来给新变量v1-v46贴标签的)变量就有46个不同值啦。
所以这都是给后面加标签做铺垫。

以下是token的help -file:
    [P] tokenize -- Divide strings into tokens 分隔字串为若干子字串

    tokenize [[`]"][string]["[']] [, parse("pchars") ]
Description
    tokenize divides string into tokens, storing the result in `1', `2', ... (the positional local macros).  Tokens are determined based on the parsing characters pchars,
    which default to a space if not specified.
Option
    parse("pchars") specifies the parsing characters.  If parse() is not specified, parse(" ") is assumed, and string is split into words.
之前在levelsof varm, local(v) 是把所有varm里的不同标签值存在v这个local macro 里(一整条长字串)
所以token `"`v'"',p("' `") 就是把 v这个local macro里的那一个长字串,根据parse设定的分隔符(' `)判定[默认分隔识别符为空格], 断开拆成一个个子字串(46个),并存在positional位置型local macro 1-46里面。看实例:
. levelsof varlab,l(v)
`"Current account balance;Percent of GDP;"' `"Current account balance;U.S. dollars;Billions"'
`"Employment;Persons;Millions"'

只截取部分,所以看到 每个断点 特征是 ` ' (即右单引号+空格+左单引号)
如果一起execute两条命令(因为是local macro)
levelsof varlab,l(v)
macro list

可以看到macro list里的v:
_v:             `"Current account balance;Percent of GDP;"' `"Current account balance;U.S. dollars;Billions"'
                `"Employment;Persons;Millions"' (截取部分)……

v里面是个长字串(由46个子字串构成,分隔判定是` ')
连续执行3条命令:
levelsof varlab,l(v)
tokenize `"`v'"',p("' `")
display "1=|`1'|, 2=|`2'|, 3=|`3'|"

得到:
1=|Current account balance;Percent of GDP;|, 2=|Current account balance;U.S. dollars;Billions|, 3=|Employment;Persons;Millions|

最后,
forvalues i=1/46{
        label variable y`i' `"``i''"'
}
forvalues: loop over consecutive values
label variable varname ["label"]
那几个引用符就是为了["label"] 这些个label两边要加双引号"label"的

`        "         `      `i'      '         "        '
所以一共4层:
1. `i'       提取label
2. `'       引用label这个字串
3. ""       加双引号
4. `'       引用整体(加完双引号的label字串)

另外用levelsof + token这个办法要么用于贴标签,要么用于换名字,
换名字的话:
指令为:(当然之前几步也有所变化)
forvalues i=1/46{
        rename y`i' ``i''
}
不能兼顾,原因有以下几个:
1、token只存1-46一次[不能给这种positional local macro更名],第二次就覆盖掉了;
2、不过问题不在token,那个可以在后面forvalues i=1/4{local lab`i'=``i'' }然后加标签的时候
forvalues i=1/46{label variable y`i' `"``lab`i'''"'},问题在于levelsof,它存变量独立值的时候,自动用升序排序,所以如果标签和变量名的升序不一致的话,就乱了;

3、如果第二次reshape 的时候带着var[即i(...)里有var]做varlab的标签 +var对y1-y46的重命名,
那就会造成冗余项过多[即便是duplicates drop之后])

目前还没想到更好的办法实现标签+命名(标签是变量的详细描述,所以较之命名更重要些,所以我是先标签,后手动命名的)



二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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