两个变量的频率表占整个样本的百分比

时间:2018-09-17 21:54:09

标签: stata

我有两个变量:

  1. ' Create a trendline for the chart Dim TL As Trendline Set TL = ActiveChart.SeriesCollection(i).Trendlines.Add(Type:=xlLinear, Forward:=0, _ Backward:=0, DisplayEquation:=1, DisplayRSquared:=0, _ Name:="LC" & CStr(i) & " Trend") ' Generate the trendline constants and place them on the summary sheet CoverSheet.Cells(CSResults(i), CSFitSlope).Value = "=INDEX(LINEST(" & YValues & "," & XValues & ",TRUE, TRUE), 1)" CoverSheet.Cells(CSResults(i), CSFitOffset).Value = "=INDEX(LINEST(" & YValues & "," & XValues & ",TRUE, TRUE), 1,2)" CoverSheet.Cells(CSResults(i), CSFitCorr).Value = "=INDEX(LINEST(" & YValues & "," & XValues & ",TRUE, TRUE), 3)" ,已婚或未婚
  2. Married,是黑色,白色或其他

我正试图在整个人群中找到RaceMarried百分比

我尝试了以下代码:

Black

但是,我要的是274/2246,而不是tab married race, row married | black other white | Total -----------+---------------------------------+---------- married | 274 18 1,150 | 1,442 | 19.00 1.25 79.75 | 100.00 -----------+---------------------------------+---------- single | 309 8 487 | 804 | 38.43 1.00 60.57 | 100.00 -----------+---------------------------------+---------- Total | 583 26 1,637 | 2,246 | 25.96 1.16 72.89 | 100.00 给我的274/1442。

2 个答案:

答案 0 :(得分:2)

您可以直接使用cell选项进行操作:

sysuse auto, clear

tabulate foreign rep78, cell

+-----------------+
| Key             |
|-----------------|
|    frequency    |
| cell percentage |
+-----------------+

           |                   Repair Record 1978
  Car type |      Poor       Fair    Average       Good  Excellent |     Total
-----------+-------------------------------------------------------+----------
  Domestic |         2          8         27          9          2 |        48 
           |      2.90      11.59      39.13      13.04       2.90 |     69.57 
-----------+-------------------------------------------------------+----------
   Foreign |         0          0          3          9          9 |        21 
           |      0.00       0.00       4.35      13.04      13.04 |     30.43 
-----------+-------------------------------------------------------+----------
     Total |         2          8         30         18         11 |        69 
           |      2.90      11.59      43.48      26.09      15.94 |    100.00 

答案 1 :(得分:1)

另一种方法是使用 Stata Journal 中的社区贡献命令groups

. sysuse auto, clear
(1978 Automobile Data)

. groups foreign rep78

  +------------------------------------+
  |  foreign   rep78   Freq.   Percent |
  |------------------------------------|
  | Domestic       1       2      2.90 |
  | Domestic       2       8     11.59 |
  | Domestic       3      27     39.13 |
  | Domestic       4       9     13.04 |
  | Domestic       5       2      2.90 |
  |------------------------------------|
  |  Foreign       3       3      4.35 |
  |  Foreign       4       9     13.04 |
  |  Foreign       5       9     13.04 |
  +------------------------------------+

请注意,与tabulate不同的是,groups可以对常规多向表执行此操作。有关概述,请参见https://www.statalist.org/forums/forum/general-stata-discussion/general/1403309-groups-updated-on-ssc。该线程包含对2017年《国家统计公报》中的文章的引用。

在撰写本文时,可以使用ssc install groups或使用search st0496_1, entry产生的可点击链接下载最新版本。

相关问题