Announcement

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

  • -esttab- Command : Export Stata Matrices into LaTeX Format with only Two Digits after the Decimal Point

    Hi everyone,

    I would like to extract a matrix and export it in LaTeX format, but only with two digits after the decimal point with -esttab-. Here is what I tried, without success:

    Code:
    / All dates, tab product_classification_encode "current" date vs. last
    tab tariff_ekon_id_encod tariff_prior_bef062021 if !missing(powers_tariff2_less_15000w) & !missing(powers_tariff2_less_15000w[_n-1]), matcell(U)
    mat list U
    
    // Convert to probabilities based on column totals
    forval k = 1/`=colsof(U)' {
       // totals each column
       local total_tar = 0
       forval l = 1/`=rowsof(U)' {
          local total_tar = `total_tar' + U[`k', `l']
       }
       di "total col `k' = " `total_tar'
       //
       forval l = 1/`=rowsof(U)' {
          mat U[`k', `l'] = U[`k', `l']/`total_tar'
       }
    }
    mat define U_prime = U'
    mat list U_prime, format(%9.2f)
    cd "${tables}"
    esttab matrix (U_prime) using TransitionalMatrix_TariffTypes_beforeJune21.tex, replace ///
    cells("r1(fmt(2)) r2(fmt(2)) r3(fmt(2)) r4(fmt(2)) r5(fmt(2)) r6(fmt(2)) r7(fmt(2)) r8(fmt(2)) ")
    Could anyone help me please? Thank you very much in advance.

    Best,
    Michael

  • #2
    estout is from SSC, as you are asked to explain in FAQ Advice #12. No reproducible example, but this may help.

    Code:
    matrix input A = (1.12845,2.7892\3.28765,4.4444)
    esttab matrix(A, fmt(%3.2f))
    Res.:

    . matrix input A = (1.12845,2.7892\3.28765,4.4444)

    .
    . esttab matrix(A, fmt(%3.2f))

    --------------------------------------
    A
    c1 c2
    --------------------------------------
    r1 1.13 2.79
    r2 3.29 4.44
    --------------------------------------

    Comment


    • #3
      Hi Andrew Musau,

      Indeed, your post in #2 helps a lot! It works as I wanted.
      Thank you so much for your help, and time!

      I apologize for failing to comply with FAQ Advice #12. Here is the matrix obtained in relation with my post #1 (better late than never):

      Code:
      . mat list U_prime
      
      U_prime[4,4]
                 c1         c2         c3         c4
      r1  .78479553  .12895582  .02588071  .08049296
      r2  .00058978  .84403885  .00018576  .00002955
      r3  .00140653  .00033292  .83420147  .00130038
      r4  .21320815  .02667241  .13973205   .9181771
      Thank you so much for your help, again.

      Comment

      Working...
      X