楼主: 一眼瞬间
3113 20

[问答] 面板数据的转化,内详,万分感谢!在第二页添加了数据Sample的附件。 [推广有奖]

  • 0关注
  • 1粉丝

讲师

50%

还不是VIP/贵宾

-

威望
0
论坛币
730 个
通用积分
0.0001
学术水平
0 点
热心指数
4 点
信用等级
0 点
经验
903 点
帖子
376
精华
0
在线时间
309 小时
注册时间
2010-3-14
最后登录
2023-8-19

楼主
一眼瞬间 发表于 2013-10-11 04:56:19 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
数据库原始的数据输出格式为:
Code
26492K(P)26492K(WC02999)26492K(WC04551)29060T(P)29060T(WC02999)29060T(WC04551)

15-04-2009


1.52

110192

0

2.27

347981

0

16-04-2009


1.5

110192

0

2.26

347981

0

17-04-2009


1.5

110192

0

2.4

347981

0

20-04-2009


1.5

110192

0

2.46

347981

0

21-04-2009


1.48

110192

0

2.47

347981

0

22-04-2009


1.47

110192

0

2.93

347981

0

23-04-2009


1.52

110192

0

3.05

347981

0

24-04-2009


1.54

110192

0

3.34

347981

0

27-04-2009


1.71

110192

0

3.3

347981

0

28-04-2009


1.8

110192

0

3.3

347981

0

29-04-2009


1.9

110192

0

3.39

347981

0

30-04-2009


2.08

110192

0

3.35

347981

0

01-05-2009


2.15

110192

0

3.54

347981

0

04-05-2009


2.55

110192

0

3.53

347981

0

05-05-2009


2.49

110192

0

3.55

347981

0

06-05-2009


2.79

110192

0

3.53

347981

0

07-05-2009


2.95

110192

0

3.36

347981

0

08-05-2009


2.99

110192

0

3.46

347981

0

11-05-2009


3

110192

0

3.35

347981

0

12-05-2009


2.99

110192

0

3.38

347981

0

13-05-2009


2.85

110192

0

3.3

347981

0

14-05-2009


2.7

110192

0

3.34

347981

0

15-05-2009


2.87

110192

0

3.37

347981

0

需要的格式为:
DateCodePWC02999WC04551

15-04-2009

26492K

1.52

110192

0

16-04-2009

26492K

1.5

110192

0

17-04-2009

26492K

1.5

110192

0

20-04-2009

26492K

1.5

110192

0

21-04-2009

26492K

1.48

110192

0

22-04-2009

26492K

1.47

110192

0

23-04-2009

26492K

1.52

110192

0

24-04-2009

26492K

1.54

110192

0

27-04-2009

26492K

1.71

110192

0

28-04-2009

26492K

1.8

110192

0

29-04-2009

26492K

1.9

110192

0

30-04-2009

26492K

2.08

110192

0

01-05-2009

26492K

2.15

110192

0

04-05-2009

26492K

2.55

110192

0

05-05-2009

26492K

2.49

110192

0

06-05-2009

26492K

2.79

110192

0

07-05-2009

26492K

2.95

110192

0

08-05-2009

26492K

2.99

110192

0

11-05-2009

26492K

3

110192

0

12-05-2009

26492K

2.99

110192

0

13-05-2009

26492K

2.85

110192

0

14-05-2009

26492K

2.7

110192

0

15-05-2009

26492K

2.87

110192

0

15-04-2009

29060T

2.27

347981

0

16-04-2009

29060T

2.26

347981

0

17-04-2009

29060T

2.4

347981

0

20-04-2009

29060T

2.46

347981

0

21-04-2009

29060T

2.47

347981

0

22-04-2009

29060T

2.93

347981

0

23-04-2009

29060T

3.05

347981

0

24-04-2009

29060T

3.34

347981

0

27-04-2009

29060T

3.3

347981

0

28-04-2009

29060T

3.3

347981

0

29-04-2009

29060T

3.39

347981

0

30-04-2009

29060T

3.35

347981

0

01-05-2009

29060T

3.54

347981

0

04-05-2009

29060T

3.53

347981

0

05-05-2009

29060T

3.55

347981

0

06-05-2009

29060T

3.53

347981

0

省略部分日期,因为太大,放不下。。。
不知道怎么转化成需要的格式,万分感谢!

二维码

扫码加我 拉你入群

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

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

关键词:Sample AMPL 万分感谢 面板数据 MPL 数据库

沙发
cactus90 学生认证  发表于 2013-10-11 07:38:19
楼主有datastream数据库,可否愿意帮忙下载QFII基金的历年收益率(年度)?

不胜感激 愿以论坛币相赠
We progress hand in hand, down to earth while aiming high, create every single miracle with a drip.[img]http:/

藤椅
一眼瞬间 发表于 2013-10-11 08:02:19
cactus90 发表于 2013-10-11 07:38
楼主有datastream数据库,可否愿意帮忙下载QFII基金的历年收益率(年度)?

不胜感激 愿以论坛币相赠
不好意思啊,版主。我那个都是别人帮下的。

格式好像不是很好用,不知道能不能转化成"Stacked Data"的格式。

板凳
cactus90 学生认证  发表于 2013-10-11 08:05:16
一眼瞬间 发表于 2013-10-11 08:02
不好意思啊,版主。我那个都是别人帮下的。

格式好像不是很好用,不知道能不能转化成"Stacked Data"的 ...
好哒 谢谢你 这个数据我已搜寻了两三个月无果 暂时先用别的数据替代着的。不过既然有还是希望能找到。

楼主的这个数据转化我不是很在行 帮顶
We progress hand in hand, down to earth while aiming high, create every single miracle with a drip.[img]http:/

报纸
yongyitian 发表于 2013-10-11 09:22:54
  1. /* Try this, you may need to convert date to a date variable */
  2. /* you may also to sort the dataset */
  3. data _null_;
  4.   length t1-t7 $20.;
  5.     if _n_ = 1 then do;
  6.   input t1 :$ t2 :$ t3 : $ t4 :$ t5 : $ t6 :$ T7 :$;   
  7.      call symput('v1', substr(t2, 8, 1));         /* variable p */;
  8.      call symput('code1', substr(t2, 1, 6));
  9.      call symput('code2', substr(t5, 1, 6));
  10.      call symput('v2', substr(t3, 8, 7));
  11.      call symput('v3', substr(t4, 8, 7));
  12.    end;
  13. datalines;
  14. code 26492K(P)  26492K(WC02999)  26492K(WC04551) 29060T(P) 29060T(WC02999) 29060T(WC04551)
  15. ; run;
  16. %put _user_;

  17. data a;
  18.   if _n_ = 1 then input @;
  19.   if _n_ > 1 then do;
  20.    input date $10. &v1 &v2 &v3 @@;
  21.         code = "&code1";
  22.         output;
  23.    input &v1 &v2 &v3;
  24.         code = "&code2";
  25.         output; end;
  26. datalines;
  27. code 26492K(P)  26492K(WC02999)  26492K(WC04551) 29060T(P) 29060T(WC02999) 29060T(WC04551)
  28. 15-04-2009  1.52 110192 0 2.27 347981 0
  29. 16-04-2009  1.5 110192 0 2.26 347981 0
  30. 17-04-2009  1.5 110192 0 2.4 347981 0
  31. 20-04-2009  1.5 110192 0 2.46 347981 0
  32. 21-04-2009  1.48 110192 0 2.47 347981 0
  33. 22-04-2009  1.47 110192 0 2.93 347981 0
  34. 23-04-2009  1.52 110192 0 3.05 347981 0
  35. 24-04-2009  1.54 110192 0 3.34 347981 0
  36. 27-04-2009  1.71 110192 0 3.3 347981 0
  37. 28-04-2009  1.8 110192 0 3.3 347981 0
  38. 29-04-2009  1.9 110192 0 3.39 347981 0
  39. 30-04-2009  2.08 110192 0 3.35 347981 0
  40. 01-05-2009  2.15 110192 0 3.54 347981 0
  41. 04-05-2009  2.55 110192 0 3.53 347981 0
  42. 05-05-2009  2.49 110192 0 3.55 347981 0
  43. 06-05-2009  2.79 110192 0 3.53 347981 0
  44. 07-05-2009  2.95 110192 0 3.36 347981 0
  45. 08-05-2009  2.99 110192 0 3.46 347981 0
  46. 11-05-2009  3 110192  0 3.35 347981 0
  47. 12-05-2009  2.99 110192 0 3.38 347981 0
  48. 13-05-2009  2.85 110192 0 3.3 347981 0
  49. 14-05-2009  2.7 110192 0 3.34 347981 0
  50. 15-05-2009  2.87 110192 0 3.37 347981 0
  51. ; run;
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
一眼瞬间 + 1 + 1 + 1 学习了!谢谢!

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

地板
一眼瞬间 发表于 2013-10-12 06:15:33
yongyitian 发表于 2013-10-11 09:22
谢谢LS指点!

It works. 只是我实际download 下来的是很大的表格,格式如第一个excel表。不知道怎么转化呢?

感激不尽!

7
一眼瞬间 发表于 2013-10-12 06:17:04
yongyitian 发表于 2013-10-11 09:22
之前找到一个是说可以用如下方法:

data sth;
set
by
array xxx x1-x1000
do i=1 to dim(xxx)
myvar = xxx; OUTPUT;
end
drop i x1-x1000;
run;

但是我还是不知道怎么work的。。。

8
一眼瞬间 发表于 2013-10-12 10:07:50
自己顶一下!

9
yongyitian 发表于 2013-10-12 11:00:49
一眼瞬间 发表于 2013-10-12 06:15
谢谢LS指点!

It works. 只是我实际download 下来的是很大的表格,格式如第一个excel表。不知道怎么转 ...
Suppose that you have imported the excel file into SAS dataset ABC, then the variable names that starting with numbers become labels of newly create variables.  You could use these labels to create the names of new variables. Since the variables are all numeric except code, a numerical array was used to track the labels in the following code.

data _null_;
    set abc (obs=1);
    array num_name{*} _numeric_;
    call symput('v1', scan(vlabel(num_name[1]), 2, '()'));    /* &v1=p        from 26492(P) */;
    call symput('v2', scan(vlabel(num_name[2]), 2, '()'));    /* &v2=WC02999  from 26492K(WC02999) */
    call symput('v3', scan(vlabel(num_name[3]), 2, '()'));    /* &v3=WC04551  from 26492K(WC04551) */
    call symput('code1', scan(vlabel(num_name[1]), 1, '()')); /* &code1 = 26492K  from 26492K(P)   */
    call symput('code2', scan(vlabel(num_name[4]), 1, '()')); /* &code2 = 29060T  from 29060T(P)   */
run;

data abc_1;
     set abc (rename=(code=date_c));
     array num{*} _numeric_;
       code = "&code1";
        &v1 = num[1];   
        &v2 = num[2];  
        &v3 = num[3];
    output;
       code = "&code2";
        &v1 = num[4];
        &v2 = num[5];
        &v3 = num[6];
    output;
   keep date_c code &v1 &v2 &v3;
run;

10
一眼瞬间 发表于 2013-10-12 12:56:52
yongyitian 发表于 2013-10-12 11:00
Suppose that you have imported the excel file into SAS dataset ABC, then the variable names that ...
Thank you so much!

Code1和code2分别是公司的identifier。只是我有上千个公司,不知道能不能不输入上千次?

我有一列是公司的Identifier(没放上去)是和日期并列的。

是和Variable对应的,例如identifier和P的组合就是这个公司的Price,和其他字母组合(WC04551)代表了其他变量。

不知道我这样描述是否不清楚?

我google了很久都没有找到解决方案。

这里提供了reshape的方案:
http://dss1.princeton.edu/usingdata/stata/dataman/reshapeds.htm

但是这个link里面只有price,我还有其他的变量。不知道怎么reshape。

感谢!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 10:04