全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
5807 6
2009-12-25
請問大家:stata資料的行列轉換問題,

目前的資料形態如下:

year     company1   company 2 .....
1990       33                  55
1991       66                  66
1992       77                  65
:

如何將資料形式,轉換如下:

company     year           var
1                   1990         33
1                   1991         66
1                   1992         77
2                   1990         55
2                   1991         66  
2                   1992         65
:

謝謝大家!
二维码

扫码加我 拉你入群

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

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

全部回复
2009-12-25 13:20:28
reshape converts data from wide to long form and vice versa.  Think of the data as a collection of
    observations x_ij.  One such collection might be

                                                   (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


    reshape converts data 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 [R] reshape for a detailed discussion and examples for both the basic and advanced syntax.


Options

    i(varlist) specifies the variable(s) whose unique values denote a logical observation.

    j(varname [values]) specifies the variable whose unique values denote a subobservation.  values list the
        unique values to be used from varname and typically is not explicitly stated since reshape will determine
        them automatically from the data.

    string specifies that the j() may contain string values.

    atwl(chars) specifies that chars should be substituted for the @ character when converting the data to the
        long form.


Examples

    . reshape long inc ue, i(id) j(year)                                                converts from wide to long  
    . reshape wide                                                                      converts back to wide      

    . reshape ..., i(id)                                                                one i() variable            
    . reshape ..., i(hid pid)                                                           two i() variables           

    . reshape long inc, i(id) j(year 80-82 85)                                          specifying j() values      

    . reshape long inc, i(id) j(sex) string                                             allow string var. in j()
二维码

扫码加我 拉你入群

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

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

2009-12-25 13:20:50
看reshape命令
二维码

扫码加我 拉你入群

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

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

2009-12-25 13:25:44
*设原始数据库是data,在默认目录中。以下可生成的a即转换后的数据库
*设公司有company1、company2、……、company20共20个。
clear
g year=.
g company=.
save a,replace
forv i=1/20{
use data,clear
keep year company`i'
ren company`i' var
g company=`i'
save b,replace
use a,clear
append using b
save a,replace
}
use a,clear
mov company year
二维码

扫码加我 拉你入群

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

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

2009-12-25 13:26:17
謝謝版主提供的訊息,我再去研究一下reshape的指令,謝謝您!
二维码

扫码加我 拉你入群

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

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

2009-12-25 13:35:54
reshape   long   company,i(year)  j(code)
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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