Matrix 如何在Stata中将一个矩阵除以另一个矩阵

Matrix 如何在Stata中将一个矩阵除以另一个矩阵,matrix,stata,division,Matrix,Stata,Division,我使用以下命令创建了两个矩阵: tab year region if x==1, matcell(cases) tab year region, matcell(total) 两个矩阵都是10列9行。 我现在想创建一个新的百分比矩阵 等于:p=(病例/总数)*100 但我在斯塔塔找不到这样做的命令?有简单的方法吗

我使用以下命令创建了两个矩阵:

tab year region if x==1, matcell(cases)  
tab year region, matcell(total)
两个矩阵都是10列9行。 我现在想创建一个新的百分比矩阵
等于:p=(病例/总数)*100


但我在斯塔塔找不到这样做的命令?有简单的方法吗
. webuse nlsw88, clear 
(NLSW, 1988 extract)

. tab race collgrad if married == 1

           |   college graduate
      race | not colle  college g |     Total
-----------+----------------------+----------
     white |       862        288 |     1,150 
     black |       224         50 |       274 
     other |        12          6 |        18 
-----------+----------------------+----------
     Total |     1,098        344 |     1,442 


. tab race collgrad

           |   college graduate
      race | not colle  college g |     Total
-----------+----------------------+----------
     white |     1,217        420 |     1,637 
     black |       480        103 |       583 
     other |        17          9 |        26 
-----------+----------------------+----------
     Total |     1,714        532 |     2,246 


. egen toshow = mean(100 * (married == 1)), by(race collgrad)

. tabdisp race collgrad, c(toshow) format(%2.1f)

----------------------------------------------
          |          college graduate         
     race | not college grad      college grad
----------+-----------------------------------
    white |             70.8              68.6
    black |             46.7              48.5
    other |             70.6              66.7
----------------------------------------------
但是让我们展示一下如何使用矩阵。请注意,您要求的是而不是在线性代数中通常理解的矩阵除法,即除法 这是基本的。现在最简单的方法就是打电话给玛塔

quietly tab race collgrad if married == 1, matcell(num) 
quietly tab race collgrad, matcell(den)
mata : st_matrix("wanted", 100 * st_matrix("num") :/ st_matrix("den"))
mat li wanted

wanted[3,2]
           c1         c2
r1   70.82991  68.571429
r2  46.666667  48.543689
r3  70.588235  66.666667
请注意,单独在Stata中执行此操作更为笨拙,但安装后完全可以使用
matewd
。但是Stata相当地将这些程序标记为“历史”程序,因为Stata 9 Mata允许一行解决方案
matewd
包含在
dm69
中,尽管在简要摘要中没有提及

. search dm69, entry historical 


STB-50  dm69  . . . . . . . . . . . . . . . . . .  Further new matrix commands
        (help matdelrc, matewm, matmad, matpow if installed)  . . .  N. J. Cox
        7/99    pp.5--9; STB Reprints Vol 9, pp.29--34
        collection of new matrix commands providing additional matrix
        checking, management, element-wise operators, maximum absolute
        difference, and power

请张贴可复制的例子。解释。因此,请转换为您自己的数据集。请注意,您的问题是
x
;现在你说的是性。原则是一样的。