楼主: 2michael1
11776 14

[Stata高级班] tab命令做出百分比表格疑问 [推广有奖]

  • 3关注
  • 0粉丝

本科生

67%

还不是VIP/贵宾

-

威望
0
论坛币
6627 个
通用积分
5.6704
学术水平
8 点
热心指数
0 点
信用等级
0 点
经验
1912 点
帖子
61
精华
0
在线时间
111 小时
注册时间
2010-7-17
最后登录
2021-11-12

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
这个问题有点难,希望有高手能解答。
本人需要做一比较复杂一点的表格:多变量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),所以那个标签名称不能完整显示的缺陷可能只能用代码来更改了。

跪求高手相助!
二维码

扫码加我 拉你入群

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

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

关键词:tab 百分比 Permanent TEMPORARY Tabulate 表格 疑问 百分比

本帖被以下文库推荐

沙发
arlionn 在职认证  发表于 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
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
8364423 + 1 + 1 + 1 对论坛有贡献
wfldragon + 1 + 1 精彩帖子

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

使用道具

藤椅
2michael1 发表于 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个,如果只是显示数字的方法会非常麻烦,所以学生需要保留名称的完整显示,请问老师有没有这类的

使用道具

板凳
arlionn 在职认证  发表于 2013-1-5 22:40:56 |只看作者 |坛友微信交流群
如果是屏幕显示必然会面临你提到的这个问题。
我建议你采用 logout 命令输出到 excel 表格中,可以采用 fix(#)  选项来控制输出的敏感度。

使用道具

报纸
2michael1 发表于 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文件是可以生成,但是,左边那一列变量依然是无法完全显示出标签全名。

请求连老师帮助!

使用道具

地板
2michael1 发表于 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)是最大值,再大的表格右边的数据全都没了。学生实在找不到任何办法解决这个问题了!求老师帮助!


使用道具

7
arlionn 在职认证  发表于 2013-1-6 10:15:37 |只看作者 |坛友微信交流群
看来只能多增加一个步骤了。
第一步,用 logout 输出表格,最左边一列输出变量名称,而非标签。
第二步,使用 des 命令呈现变量名称和对应的标签,然后把标签那一列贴入第一步中对应的变量列。

使用道具

8
2michael1 发表于 2013-1-6 23:35:38 |只看作者 |坛友微信交流群
arlionn 发表于 2013-1-6 10:15
看来只能多增加一个步骤了。
第一步,用 logout 输出表格,最左边一列输出变量名称,而非标签。
第二步, ...
请连老师说具体点可以吗?具体命令是怎么写的呢?学生不懂~求助!下面是isco1d,isco3d和nace1d三个职业划分变量的数字文字对应表:isco1d
0        Armed Forces
100        Legislators, Senior Officials&Managers
200        Professionals
300        Technicians&Associate Professionals
400        Clerks
500        Service workers&shop&market sales workers
600        Skilled Agricultural&fishery workers
700        Craft&related trades workers
800        Plant&machine operators&assemblers
900        Elementary occupations
999        Not applicable (WSTATOR=3-5,9)



isco3d
10        Armed forces
100        Armed Forces
110        Legislators and Senior Officials
111        Legislators
112        Senior government officials
113        Traditional chiefs and heads of villages
114        Senior officials of special-interest organisations
120        Corporate Managers
121        Directors and chief executives
122        Production and operations department managers
123        Other department managers
130        Managers of Small Enterprises
131        General managers
210        Physics, mathematical and engineering science professionals
211        Physicists, chemists and related professionals
212        Mathematicians, statisticians and related professionals
213        Computing professionals
214        Architects, engineers and related professionals
220        Life science and health professionals
221        Life science professionals
222        Health professionals (except nursing)
223        Nursing and midwifery professionals
230        Teaching professionals
231        College, university and higher education teaching profession
232        Secondary education teaching professionals
233        Primary and pre-primary education teaching professionals
234        Special education teaching professionals
235        Other teaching professionals
240        Other professionals
241        Business professionals
242        Legal professionals
243        Archivists, librarians and related information professionals
244        Social science and related professionals
245        Writers and creative or performing artists
246        Religious professionals
310        Physical and engineering science associate professionals
311        Physical and engineering science technicians
312        Computer associate professionals
313        Optical and electronic equipment operators
314        Ship and aircraft controllers and technicians
315        Safety and quality inspectors
320        Life science and health associate professionals
321        Life science technicians and related associate professionals
322        Modern health associate professionals (except nursing)
323        Nursing and midwifery associate professionals
324        Traditional medicine practitioners and faith healers
330        Teaching associate professionals
331        Primary education teaching associate professionals
332        Pre-primary education teaching associate professionals
333        Special education teaching associate professionals
334        Other teaching associate professionals
340        Other associate professionals
341        Finance and sales associate professionals
342        Business services agents and trade brokers
343        Administrative associate professionals
344        Customs, tax and related government associate professionals
345        Police inspectors and detectives
346        Social work associate professionals
347        Artistic, entertainment and sports associate professionals
348        Religious associate professionals
410        Office clerks
411        Secretaries and keyboard-operating clerks
412        Numerical clerks
413        Material-recording and transport clerks
414        Library, mail and related clerks
419        Other office clerks
420        Customer services clerks
421        Cashiers, tellers and related clerks
422        Client information clerks
510        Personal and protective services workers
511        Travel attendants and related workers
512        Housekeeping and restaurant services workers
513        Personal care and related workers
514        Other personal services workers
515        Astrologers, fortune-tellers and related workers
516        Protective services workers
520        Models, salespersons and demonstrators
521        Fashion and other models
522        Shop salespersons and demonstrators
523        Stall and market salespersons
610        Skilled agricultural and fishery workers
611        Market gardeners and crop growers
612        Market-oriented animal producers and related workers
613        Market-oriented crop and animal producers
614        Forestry and related workers
615        Fishery workers, hunters and trappers
621        Subsistence agricultural and fishery workers
710        Extraction and building trades workers
711        Miners, shotfirers, stone cutters and carvers
712        Building frame and related trades workers
713        Building finishers and related trades workers
714        Painters, building structure cleaners and related trades wor
720        Metal, machinery and related trades workers
721        Metal moulders etc and related trades workers
722        Blacksmiths, tool-makers and related trades workers
723        Machinery mechanics and fitters
724        Electrical and electronic equipment mechanics and fitters
730        Precision,handicraft,craft printing & related trades workers
731        Precision workers in metal and related materials
732        Potters, glass-makers and related trades workers
733        Handicraft workers in wood,textile, leather and related mate
734        Printing and related trades workers
740        Other craft and related trades workers
741        Food processing and related trades workers
742        Wood treaters, cabinet-makers and related trades workers
743        Textile, garment and related trades workers
744        Pelt, leather and shoemaking trades workers
810        Stationary plant and related operators
811        Mining- and mineral-processing-plant operators
812        Metal-processing-plant operators
813        Glass, ceramics and related plant operators
814        Wood-processing- and papermaking-plant operators
815        Chemical-processing-plant operators
816        Power-production and related plant operators
817        Automated-assembly-line and industrial-robot operators
820        Machine operators and assemblers
821        Metal- and mineral-products machine operators
822        Chemical-products machine operators
823        Rubber- and plastic-products machine operators
824        Wood-products machine operators
825        Printing-, binding- and paper-products machine operators
826        Textile-, fur- and leather-products machine operators
827        Food and related products machine operators
828        Assemblers
829        Other machine operators and assemblers
830        Drivers and mobile plant operators
831        Locomotive-engine drivers and related workers
832        Motor-vehicle drivers
833        Agricultural and other mobile-plant operators
834        Ships' deck crews and related workers
910        Sales and services elementary occupations
911        Street vendors and related workers
912        Shoe cleaning and other street services elementary occupatio
913        Domestic and related helpers, cleaners and launderers
914        Building caretakers, window and related cleaners
915        Messengers, porters, doorkeepers and related workers
916        Garbage collectors and related labourers
920        Agricultural, fishery and related labourers
921        Agricultural, fishery and related labourers
930        Labourers in mining, construction, manufacturing & transport
931        Mining and construction labourers
932        Manufacturing labourers
933        Transport labourers and freight handlers
999        Not applicable
1000        .
1001        11
1002        247
1003        300
1004        800
1005        Health professionals(except nursing)
1006        Modern health associate professionals(except nursing)


nace1d
1        .
2        9
3        Accommodation and food service activities
4        Activities of extraterritorial organisations and bodies
5        Activities of households as employers; undifferentiated goods- and services-producing        activities        of
        households for own use
6        Administrative and support service activities
7        Agriculture, forestry and fishing
8        Arts, entertainment and recreation
9        Construction
10        Education
11        Electricity, gas, steam and air conditioning supply
12        Financial and insurance activities
13        Human health and social work activities
14        Information and communication
15        Manufacturing
16        Mining and quarrying
17        Other service activities
18        Professional, scientific and technical activities
19        Public administration and defence; compulsory social security
20        Real estate activities
21        Transportation and storage
22        Water supply; sewerage, waste management and remediation activities
23        Wholesale and retail trade; repair of motor vehicles and motorcycles


使用道具

9
2michael1 发表于 2013-1-6 23:40:03 |只看作者 |坛友微信交流群
arlionn 发表于 2013-1-6 10:15
看来只能多增加一个步骤了。
第一步,用 logout 输出表格,最左边一列输出变量名称,而非标签。
第二步, ...
连老师,您的意思是,用logout输出表格到word文档,然后再用labelbook列出变量数字文字对应表,把其中的变量标签复制替代logout出来的表格左列吗?
学生也想这样做,可是问题在于用logout无法生成excel的xlsx结尾的excel格式文档,只能生成xml的格式,这种格式excel打不开哦老师,该咋办?

使用道具

10
2michael1 发表于 2013-1-6 23:44:54 |只看作者 |坛友微信交流群
arlionn 发表于 2013-1-5 22:40
如果是屏幕显示必然会面临你提到的这个问题。
我建议你采用 logout 命令输出到 excel 表格中,可以采用 fi ...
老师,您说的,“用 logout 输出表格,最左边一列输出变量名称,而非标签”这个命令该怎么操作呢?

使用道具

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

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

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

GMT+8, 2024-11-5 18:29