Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • David Rolls
    started a topic matrix division

    matrix division

    Hi,

    I have two variables for which I use the sum command to aggregate the values, so I end-up with two numbers. I want to export these two results so I use the matrix function. I also want to divide these two results together and export the result too. It is here that I have a problem. I do not find how to proceed for the division.

    I have the following code :

    Code:
    .estpost tabstat VARIABLE1 if year == 2008, statistics(sum)
    .esttab, wide nonumber cell("sum(label(Total Variable1 in 2008))")
    .mat II = e(sum)'
    .estpost tabstat VARIABLE2 if year == 2008, statistics(sum)
    .esttab, wide nonumber cell("sum(label(Total Variable2 in 2008))")
    .mat JJ = e(sum)'
    .putexcel set "name.xlsx", replace
    .putexcel A3 = "2008"
    .putexcel B3 = matrix(II)
    .putexcel C3 = matrix(JJ)

    Thank you in advance.

    David

  • David Rolls
    replied
    Thank you a lot. It works perfectly.

    Best regards,

    David

    Leave a comment:


  • William Lisowski
    replied
    I think the most straightforward way of accomplishing the desired element-by-element division is using Mata's :/ operator.
    Code:
    . matrix list ii
    
    ii[2,2]
        c1  c2
    r1  10  20
    r2  30  40
    
    . matrix list jj
    
    jj[2,2]
        c1  c2
    r1   5   5
    r2  10  10
    
    . mata: st_matrix("kk", st_matrix("ii") :/ st_matrix("jj") )
    
    . matrix list kk
    
    kk[2,2]
        c1  c2
    r1   2   4
    r2   3   4

    Leave a comment:

Working...
X