楼主: cuiyanliliubing
5104 13

[其他] stata 数据合并问题 [推广有奖]

  • 0关注
  • 0粉丝

初中生

90%

还不是VIP/贵宾

-

威望
0
论坛币
11 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
108 点
帖子
21
精华
0
在线时间
7 小时
注册时间
2010-2-25
最后登录
2010-4-18

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
急球stata命令阿,我有大样本,先放个小的在这里,请大家帮忙看看阿,如何将表一变成表2,拜谢了阿
表一:
代码2005
代码2006
代码2007
X2005
X2006
X2007
1
2
3
12
15
11
2
3
4
14
14
15
3
4
5
17
13
167

5
7

16
21


8


56


9


44


10


37


表2;
代码
year
x
1
2005
12
1
2006
0
1
2007
0
2
2005
14
2
2006
15
2
2007
0
3
2005
17
3
2006
14
3
2007
15
4
2005
0
4
2006
13
4
2007
15
5
2005
0
5
2006
16
5
2007
167
下同,省略了


二维码

扫码加我 拉你入群

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

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

关键词:Stata tata 数据合并 stata命令 year 如何 样本

沙发
cuiyanliliubing 发表于 2010-4-17 10:14:10 |只看作者 |坛友微信交流群
表2格式没弄好,大家见谅阿

使用道具

藤椅
cuiyanliliubing 发表于 2010-4-17 10:15:22 |只看作者 |坛友微信交流群
代码        year        x
1        2005        12
1        2006        0
1        2007        0
2        2005        14
2        2006        15
2        2007        0
3        2005        17
3        2006        14
3        2007        15
4        2005        0
4        2006        13
4        2007        15
5        2005        0
5        2006        16
5        2007        167
下同,省略了

使用道具

板凳
cuiyanliliubing 发表于 2010-4-17 10:16:03 |只看作者 |坛友微信交流群
我把表2又贴了下

使用道具

报纸
ctx5518 发表于 2010-4-17 10:21:36 |只看作者 |坛友微信交流群
reshape long

使用道具

地板
cuiyanliliubing 发表于 2010-4-17 10:24:26 |只看作者 |坛友微信交流群
能说具体点吗,我不太会阿

使用道具

7
cuiyanliliubing 发表于 2010-4-17 10:28:25 |只看作者 |坛友微信交流群
多变量如何排列呢

使用道具

8
蓝色 发表于 2010-4-17 10:35:46 |只看作者 |坛友微信交流群
help reshape                                                                                      dialog:  reshape
------------------------------------------------------------------------------------------------------------------

Title

    [D] reshape -- Convert data from wide to long form and vice versa


Syntax

    Basic Syntax

        reshape long stubnames, i(varlist) [options]

        reshape wide stubnames, i(varlist) [options]

        reshape error


               long
              +------------+                  wide
              | i  j  stub |                 +----------------+
              |------------|                 | i  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 |                 +----------------+
              +------------+


              To go from long to wide:

                                                j existing variable
                                               /
                    reshape wide stub, i(i) j(j)


              To go from wide to long:

                    reshape long stub, i(i) j(j)
                                               \
                                                j new variable


              To go back to long after using reshape wide:
              
                    reshape long

              
              To go back to wide after using reshape long:

                    reshape wide      


         options                    description
       -----------------------------------------------------------------------------------------------------------
       * i(varlist)                 use varlist as the ID variables
         j(varname [values])        long->wide: varname, existing variable
                                    wide->long: varname, new variable
                                    optionally specify values to subset varname
         string                     varname is a string variable (default is numeric)
       -----------------------------------------------------------------------------------------------------------
        * i(varlist) is required.

        where values is  #[-#] [...]              if varname is numeric
                                                    (default)
                         "string" ["string" ...]  if varname is string

        and where stubnames are variable names (long->wide), or stubs of variable names (wide->long), and either
        way, may contain @, denoting where j appears or is to appear in the name.

        In the example above, when we wrote "reshape wide stub", we could have written "reshape wide stub@"
        because j by default ends up as a suffix.  Had we written stu@b, then the wide variables would have been
        named stu1b and stu2b.


    Advanced syntax

        reshape i varlist

        reshape j varname [values] [, string]

        reshape xij fvarnames [, atwl(chars)]

        reshape xi [varlist]

        reshape [query]

        reshape clear


Menu

    Data > Create or change data > Other variable-transformation commands > Convert data between wide and long


Description

    reshape converts data from wide to long form and vice versa.


Options

    i(varlist) specifies the variables whose unique values denote a logical observation. i() is required.

    j(varname [values]) specifies the variable whose unique values denote a subobservation.  values lists the
        unique values to be used from varname, which typically are not explicitly stated because reshape will
        determine them automatically from the data.

    string specifies that j() may contain string values.

    atwl(chars), available only with the advanced syntax and not shown in the dialog box, specifies that chars
        be substituted for the @ character when converting the data from wide to long form.


Remarks

    Before using reshape, you need to determine whether the data are in long or wide form.  You also must
    determine the logical observation (i) and the subobservation (j) by which to organize the data.  Suppose
    that you had the following data, which could be organized in wide or long form as follows:


                                                  (wide form)           

                                         i         ....... x_ij ........
                                         id  sex   inc80   inc81   inc82
                                         -------------------------------
                                          1    0    5000    5500    6000
                                          2    1    2000    2200    3300
                                          3    0    3000    2000    1000


                                                   (long form)      

                                              i     j           x_ij
                                             id   year   sex    inc
                                             -----------------------
                                              1     80     0   5000
                                              1     81     0   5500
                                              1     82     0   6000
                                              2     80     1   2000
                                              2     81     1   2200
                                              2     82     1   3300
                                              3     80     0   3000
                                              3     81     0   2000
                                              3     82     0   1000


    Given these data, you could use reshape to convert from one form to the other:

        . reshape long inc, i(id) j(year)  (goes from top form to bottom)
        . reshape wide inc, i(id) j(year)  (goes from bottom form to top)

    See [D] reshape for a detailed discussion and examples for both the basic and advanced syntax.

使用道具

9
蓝色 发表于 2010-4-17 10:37:49 |只看作者 |坛友微信交流群
这就是stata中的reshape的帮助
你自己打开看一下,试试那个例子就会了

使用道具

10
cuiyanliliubing 发表于 2010-4-17 11:16:43 |只看作者 |坛友微信交流群
试过了,还是不行啊

使用道具

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

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

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

GMT+8, 2024-5-7 17:11