全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 统计软件培训班VIP答疑区
12698 14
2013-01-05
这个问题有点难,希望有高手能解答。
本人需要做一比较复杂一点的表格:多变量table,显示某个数据所占总体数据百分比,详细点说,我这些变量都是类别变量(蓝色),isco1d这个变量是这个问题中的主要变量,它的意义是欧盟对职业的划分(比如500代表Service workers and shop and market sales workers),所以当你tab了后就会知道每个职业占这个数据文件的百分比,而我就是要计算isco1d在一定划分和限制条件下占整个数据文件中的百分比。这些划分限制条件就是sex(M/F), ftpt(full time/part time), temp(permanent job/temporary job), age_G(age group) 和refyear(year)。总的来说,我最想要的理想表格形式是这样的:
Year
isco1d

permanent  job

temporary  job

FT

PT

FT

PT

Age_Group A

Age_Group B

Age_Group A

Age_Group B

Age_Group A

Age_Group B

Age_Group A

Age_Group B

Male

A

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

B

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

C

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

D

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

E

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

F

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

Female

A

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

B

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

C

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

D

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

E

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

F

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%

isco1d%



可是往往事与愿违啊,如果有哪位高人能做出以上表格,小弟甘愿拜为其徒弟!!

所以目前唯一能符合本人需求的命令和方法有以下两个:

by refyear ftpt temp sex,sort: tabulate isco1d age_G [fw=coeff], row nofreq w
可是这个命令有两个缺陷,一是表格内的标签不能够显示完整,无法调整stata表格的宽度(特别是对变量标签的宽度);二是大部分变量,比如 refyear ftpt temp sex 这四个分类变量被排除在表格外,本人实在很想把这四个类别变量列进表格。

于是乎就想到以下命令:
table isco1d age_G ftpt [fweight = coeff], by(sex) row center
可是以上命令又有2个缺陷,一是无法显示百分比(%)只能显示频数(freq);二是变量标签依然无法按照自己要求变宽,导师变量标签显示一半就没了信息了。

有没有高人能够做到能让两个方法的缺陷都消失呢?特别是第二个,第二个table命令最符合我理想的图形,但是却无法显示百分比这点比较让我郁闷,听说这两个命令都没法改标签的长度(wide),所以那个标签名称不能完整显示的缺陷可能只能用代码来更改了。

跪求高手相助!
二维码

扫码加我 拉你入群

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

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

全部回复
2013-1-5 11:43:32
我的笔记中有些新的命令,供参考。

*-类别变量列表分析

  *-一维表
    fre: module to display one-way frequency table
        *-相对于 tabulate 命令而言, 结果的输出和追加比较方便

  *-二维表
    help tabulate
        help tab2way   // tabulate 的姊妹命令,呈现百分比
        sysuse nlsw88, clear
        tab     industry married
        tab2way industry married, cellpct nofreq
        *'TAB2WAY': module to handle two-way tables with percentages

  *-tabdisp  (非常灵活的命令)
    help tabdisp
        sysuse auto, clear
        tabdisp foreign rep78, cell(mpg)
        
  *-tabm
    help tabm
        sysuse nlsw88, clear
        tabm occu race married
    Cox, N.J. and Kohler, U. 2003.  
            On structure and shape: the case of multiple responses.  Stata
        Journal 3: 81-99.
    Jann, B. 2005. Tabulation of multiple responses.  Stata Journal 5: 92-122.

  *-mrtab (非常强大的命令)
    *-多元类别变量的统计和组间差异检验
        * mrgraph: to produce plots of multiple response distributions

  *-三维表
    help tab3way
        
    sysuse auto, clear
    egen price_cat = cut(price), group(4)
    tab3way price_cat rep78 foreign, rowpct colp format(%5.3f)
   
        egen weight_cat = cut(weight), group(2)
    bysort weight_cat: tab3way price_cat rep78 foreign, allp allt usemiss
    bysort weight_cat: tab3way price_cat rep78 foreign, allp usemiss
        
        sysuse nlsw88, clear
        tab3way union married race, rowpct format(%4.2f)
        bysort union married: tab3way

  *-列表绘图
    sysuse auto, clear
    egen meanprice = mean(price), by(foreign rep78)
    tableplot rbar meanprice for rep78
    tableplot rbar meanprice for rep78, showval(format(%4.0f))
        
        sysuse nlsw88, clear
        local v "married race"
        local v "industry race"
        egen av_wage = mean(wage), by(`v')
    tableplot rbar av_wage `v'
        tableplot rbar av_wage `v', showval(format(%4.0f))        

        *-Other commands:
        help tabplot
        tabl.  one-var tabulate with labels and numeric codes
        tabw   Tabulating the counts of multiple categorical variables

*-New commands
  digdis -- Analysis of digit distributions
二维码

扫码加我 拉你入群

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

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

2013-1-5 22:21:10
arlionn 发表于 2013-1-5 11:43
我的笔记中有些新的命令,供参考。

*-类别变量列表分析
非常感谢连老师,tab3way很符合我的大部分要求,但是老师,另一个难题是关于标签的宽度,比如ISCO1D这个变量,500是标示“Service workers and shop and market sales workers”这么长名称的一个职业类别,当用tab3way的时候,他在表格的左边,它的名称不能完全显示出来,如下图:
ISCO1Dage15-24age 25-64age65-95Total
Legislators, Senior O

10.12

87.71

2.17

100

Professionals

1.87

89.65

8.48

100

Technicians and Assoc

6.18

91.74

2.08

100

Clerks

4.09

95.91

0

100

Service workers and s

1.26

96.77

1.97

100

Skilled Agricultural

3.38

82.01

14.61

100

Craft and related tra

25.33

74.67

0

100

Plant and machine ope

0

100

0

100

Elementary occupation

0

92.72

7.28

100

Total

4.2

88.57

7.23

100

左边的名称不能完全显示出来,有没有命令可以增加左边标签的宽度呢??由于后面有一个ISCO3D的变量,其职业划分达到144个,如果只是显示数字的方法会非常麻烦,所以学生需要保留名称的完整显示,请问老师有没有这类的

二维码

扫码加我 拉你入群

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

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

2013-1-5 22:40:56
如果是屏幕显示必然会面临你提到的这个问题。
我建议你采用 logout 命令输出到 excel 表格中,可以采用 fix(#)  选项来控制输出的敏感度。
二维码

扫码加我 拉你入群

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

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

2013-1-5 23:51:16
arlionn 发表于 2013-1-5 22:40
如果是屏幕显示必然会面临你提到的这个问题。
我建议你采用 logout 命令输出到 excel 表格中,可以采用 fi ...
谢谢连老师,但是随之而来的有2个问题,我使用的命令是这样的:
logout,save(mylogout) excel replace fix(3):tab3way isco1d age_G sex[fw=coeff], rowpct colp format(%5.3f)
您在课中说fix(3)是最好的,我不清楚里面的3代表什么意思。

但是生成的是xml格式的文件而不是excel的xlsx格式的文件,用excel打不开。如果我把excel改为word,生成的word文件是可以生成,但是,左边那一列变量依然是无法完全显示出标签全名。

请求连老师帮助!
二维码

扫码加我 拉你入群

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

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

2013-1-6 00:05:40
arlionn 发表于 2013-1-5 22:40
如果是屏幕显示必然会面临你提到的这个问题。
我建议你采用 logout 命令输出到 excel 表格中,可以采用 fi ...
连老师,感谢您的回复,我刚用了一个命令简单:
logout,save(C:\Users\Desktop\log) word replace fix(32):tabulate isco1d age_G, row nofreq
然后结果如下:

Occupation  (ISCO at 1

digit level, deliver

  

ed as 3-digit  variabl

  
  

RECODE  of age (Age of interviewed person)

  
  

e to  distinguish

  
  

age  0-14  age 15-24  age 25-64   age 65-95

  
  

  
  

  
  

Armed Forces

  
  

0.00      16.54      83.37       0.09

  
  

Legislators,  Senior O

  
  

0.00       2.94      95.45       1.61

  
  

Professionals

  
  

0.00       3.28      95.24       1.48

  
  

Technicians  and Assoc

  
  

0.00      12.26      86.97       0.77

  
  

Clerks

  
  

0.00      14.73      84.89       0.38

  
  

Service  workers and s

  
  

0.00      22.14      77.21       0.65

  
  

Skilled  Agricultural

  
  

0.00       5.77      85.48       8.75

  
  

Craft and  related tra

  
  

0.00      26.74      72.95       0.31

  
  

Plant and  machine ope

  
  

0.00       8.71      90.93       0.36

  
  

Elementary  occupation

  
  

0.00       7.60      91.22       1.18

  
  

Not applicable  (WSTAT

  
  

31.47      10.92      28.58      29.03

  
  

.

  
  

0.00      20.34      77.97       1.69

  
  

  
  

  
  

Total

  
  

16.98      12.19      54.61      16.23

  
  

  
  

  

smcl

最后还是没能把左边的那一列标签完全显示出来(被截了1/3)左右,比在结果窗口好一点点,请教老师,有没有任何办法能完全显示左边那一列标签呢?发现fix(32)是最大值,再大的表格右边的数据全都没了。学生实在找不到任何办法解决这个问题了!求老师帮助!


二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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