楼主: crystal_chenwei
30793 14

[其他] stata中reshape遇到问题 [推广有奖]

  • 3关注
  • 0粉丝

已卖:1份资源

高中生

80%

还不是VIP/贵宾

-

威望
0
论坛币
1433 个
通用积分
0.6980
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
873 点
帖子
12
精华
0
在线时间
62 小时
注册时间
2010-8-25
最后登录
2023-6-1

楼主
crystal_chenwei 发表于 2015-8-13 21:57:06 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
想用stata将wide数据转换成long我打了reshape long sheet36, i(countryname) j(year)
但是stata显示,求大侠释疑
我把原数据放入附件 请各位帮忙看看

no xij variables found
    You typed something like reshape wide a b, i(i) j(j).
    reshape looked for existing variables named a# and b# but could not find any.  Remember this picture:

         long                                wide
        +---------------+                   +------------------+
        | i   j   a   b |                   | i   a1 a2  b1 b2 |
        |---------------| <--- reshape ---> |------------------|
        | 1   1   1   2 |                   | 1   1   3   2  4 |
        | 1   2   3   4 |                   | 2   5   7   6  8 |
        | 2   1   5   6 |                   +------------------+
        | 2   2   7   8 |
        +---------------+

        long to wide: reshape wide a b, i(i) j(j)    (j existing variable)
        wide to long: reshape long a b, i(i) j(j)    (j    new   variable)


原数据
Country  Name1960 [YR1960]1961 [YR1961]1962 [YR1962]1963 [YR1963]1964 [YR1964]
Argentina

2.685281

2.432308

2.328961

2.285788

2.23608

Australia

2.783396

2.493808

2.922755

2.390362

2.424252

Brazil

5.204268

5.102537

5.071378

5.018287

4.916381

China

4.935495

2.053596

3.873678

5.493641

5.327344

France

2.447048

2.543971

2.86061

3.354723

3.186223

Germany

1.251659

1.20737

0.970049

1.015019

0.895597

India

2.347275

2.589566

3.0413

3.063189

3.09739

Indonesia

3.998054

4.01274

4.02288

4.048851

4.074228

Italy

2.836401

1.498807

1.506833

1.551287

1.636027



二维码

扫码加我 拉你入群

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

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

关键词:reshape Stata Shape tata APE something existing

相思千里暮云深

沙发
raiman 发表于 2015-8-13 23:25:11
1. 用stata12打不开你附件的数据,提示如下错误:sheet36.dta not Stata format

2. 把命令 reshape long sheet36, i(countryname) j(year)中的 sheet36 改为YR试一下。long 后面不是跟着数据文件名“sheet36”!而是第一行第二列开始的stubnames. 比如数据格式为如下wide形式,要将wide转为long,则命令为: reshape long stub, i(id) j(year)

           long
        +------------+                             wide
        |id  year  stub|                      +------------------+
        |-----------------|                        |id  stub1 stub2|
        | 1    1    4.1  |     reshape    |------------------------|
        | 1    2    4.5  |   <--------->      |1     4.1      4.5  |
        | 2    1    3.3  |                         |2     3.3      3.0  |
        | 2    2    3.0  |                         +--------------------+
        +---------------+


3. 用我的数据data1,命令如下:reshape long yr, i(countryname) j(year),可行。

data1.dta

1.91 KB

已有 3 人评分经验 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 热心帮助其他会员
wangbaofu + 1 + 1 + 1 精彩帖子
夏目贵志 + 10 + 1 + 2 热心帮助其他会员

总评分: 经验 + 10  学术水平 + 5  热心指数 + 6  信用等级 + 4   查看全部评分

藤椅
crystal_chenwei 发表于 2015-8-14 11:54:56
raiman 发表于 2015-8-13 23:25
1. 用stata12打不开你附件的数据,提示如下错误:sheet36.dta not Stata format

2. 把命令 reshape long ...
谢谢您的回复!!问题解决了!
我的data打不开可能是因为我用13保存的
的确reshape long 后面应该跟subname
我之前是跟着《应用stata做统计分析》这本书做的
里面对long后面跟的变量解释有些错误(书里写long后面跟一个新变量...) 所以才会这样。。

真的再次感谢您!
相思千里暮云深

板凳
sinopart 发表于 2016-5-29 11:35:40
raiman 发表于 2015-8-13 23:25
1. 用stata12打不开你附件的数据,提示如下错误:sheet36.dta not Stata format

2. 把命令 reshape long ...
图片2.png
您好这是我的原始数据,使用命令  reshape long Rank, i(cncode) j(year) string
为何报错no xij variables found
多谢指教

图片2.png (31.96 KB)

图片2.png

图片2.png (31.96 KB)

图片2.png

我并非天生璀璨的钻石,但我希望时间和磨砺令我焕发别样光芒

报纸
raiman 发表于 2016-5-30 11:05:28
sinopart 发表于 2016-5-29 11:35
您好这是我的原始数据,使用命令  reshape long Rank, i(cncode) j(year) string
为何报错no xij vari ...
命令使用上没问题,可能是数据有问题。估计要实际操作下你的stata格式的数据才能找到问题。不介意的话把你的数据传上来(.dta格式的,为防泄密可传部分数据)

地板
sinopart 发表于 2016-5-30 14:47:35
raiman 发表于 2016-5-30 11:05
命令使用上没问题,可能是数据有问题。估计要实际操作下你的stata格式的数据才能找到问题。不介意的话把你 ...
VA.dta (401.08 KB)
多谢啦
我并非天生璀璨的钻石,但我希望时间和磨砺令我焕发别样光芒

7
sinopart 发表于 2016-5-30 14:55:30
sinopart 发表于 2016-5-30 14:47
多谢啦
reshape long rank, i(id code) j(year)
(note: j = 0 1 2 3 4 5 6 7 8 9 10 11 12 99)
(note: rank0 not found)
(note: rank1 not found)
(note: rank2 not found)
(note: rank3 not found)
(note: rank4 not found)
(note: rank5 not found)
(note: rank6 not found)
(note: rank7 not found)
(note: rank8 not found)
(note: rank9 not found)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                      215   ->    3010
Number of variables                  18   ->      16
j variable (14 values)                    ->   year
xij variables:
                 rank0 rank1 ... rank99   ->   rank
-----------------------------------------------------------------------------
我的原始数据是1999至2012年,后来发现跑命令时候总提示出错,看了例子觉得应该是我的year和例子的格式不太一样,就把year的格式改为99,00,01,02,然后结果中00-09数据都缺失,我觉得是系统不认00-09这种时间模式,求各位指教该怎么解决,多谢

8
sinopart 发表于 2016-5-30 14:56:30
sinopart 发表于 2016-5-30 14:47
多谢啦
reshape long rank, i(id code) j(year)
(note: j = 0 1 2 3 4 5 6 7 8 9 10 11 12 99)
(note: rank0 not found)
(note: rank1 not found)
(note: rank2 not found)
(note: rank3 not found)
(note: rank4 not found)
(note: rank5 not found)
(note: rank6 not found)
(note: rank7 not found)
(note: rank8 not found)
(note: rank9 not found)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                      215   ->    3010
Number of variables                  18   ->      16
j variable (14 values)                    ->   year
xij variables:
                 rank0 rank1 ... rank99   ->   rank
-----------------------------------------------------------------------------
我的原始数据是1999至2012年,后来发现跑命令时候总提示出错,看了例子觉得应该是我的year和例子的格式不太一样,就把year的格式改为99,00,01,02,然后结果中00-09数据都缺失,我觉得是系统不认00-09这种时间模式,求各位指教该怎么解决,多谢

9
jlu-allen 发表于 2016-5-30 23:11:19
sinopart 发表于 2016-5-30 14:56
reshape long rank, i(id code) j(year)
(note: j = 0 1 2 3 4 5 6 7 8 9 10 11 12 99)
(note: rank0 n ...
出现同样问题,解决了吗?

10
sinopart 发表于 2016-6-1 15:56:17
jlu-allen 发表于 2016-5-30 23:11
出现同样问题,解决了吗?
解决了我把时间改成11、12、13、14这样的。请问您之前试过四位数字年份格式吗?比如1999,2000,2001
已有 1 人评分学术水平 收起 理由
Yon0606 + 1 精彩帖子

总评分: 学术水平 + 1   查看全部评分

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

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