Announcement

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

  • Export handmade matrix to latex with math underscores in (long) row titles

    I always have trouble exporting handmade Stata matrices to Latex when I want to use math in the rowtitles. Here is a good example, below. The command frmttable allows me to specify the row title that I want, but it converts "_" to "\_" in the .tex file, and there is no way to stop this (i.e. I can't use substitute(\_ _) as I do with esstab). As far as I can see, outtable does not provide options for specifying row or column titles, you have to provide the names directly to the matrix. However, Stata deems my matrix name too long. (And in fact, even if I instead write matrix rownames Kest = "$ K $") the dollar signs do not carry through, despite the asis option.)

    So neither of these methods allows me to properly export my matrix with the titles I want. Is there some work-around, or some other export method I don't know about?

    Code:
    clear matrix
    local rows = 1
    local cols 2
    capture matrix Kest = J(`rows',`cols',.)
    mat Kest[1,1]= 1
    mat Kest[1,2]= 2
    
    % Try with frmttable
    frmttable using "${TABLES}/Tab_Kest_A.tex", ///
        tex statmat(Kest) sdec(3) fragment replace ///
        ctitle("", "First Est","Second Est") ///
        rtitle("$ K \equiv \phi_{\varepsilon} / \phi_{\gamma x}$")
        
    % Try with outtable
    matrix rownames Kest = "$ K \equiv \phi_{\varepsilon} / \phi_{\gamma x}$"
    matrix colnames Kest = "First Est" "Second Est"
    outtable using "${TABLES}/Tab_Kest_B", ///
        mat(Kest) replace asis

  • #2
    I don't use either of these community contributed commands. Please note the advice in FAQ #12 to identify the provenance of such commands. Why don't you use esttab (Stata Journal) that you reference?

    Comment


    • #3
      I do for regression. But as far as I know / see in the help (http://repec.org/bocode/e/estout/hlp_esttab.html) esttab is only for outputting regression coefficients. Is there some way to feed in a handmade Stata matrix?

      Comment


      • #4
        Yes. I would specify the row names with illegal name characters as row equation names. With your example in #1:

        Code:
        clear matrix
        local rows = 1
        local cols 2
        capture matrix Kest = J(`rows',`cols',.)
        mat Kest[1,1]= 1
        mat Kest[1,2]= 2
        mat roweq Kest = "$ K \equiv \phi_{\varepsilon} / \phi_{\gamma x}$"
        matrix colnames Kest = "First Est" "Second Est"
        esttab matrix(Kest), eqlabels(,merge) tex substitute(:r1 "")
        Res.:

        Code:
        . 
        . esttab matrix(Kest), eqlabels(,merge) tex substitute(:r1 "")
        
        \begin{tabular}{l*{2}{c}}
        \hline\hline
                    &        Kest&            \\
                    &   First Est&  Second Est\\
        \hline
        $ K \equiv \phi_{\varepsilon} / \phi_{\gamma x}$&           1&           2\\
        \hline\hline
        \end{tabular}

        Comment


        • #5
          Wow this works beautifully, thank you so much! Out of curiosity, how would one know that a matrix could be inputted this way? Because the link I gave in #1 (and the help for esstab) explicitly says that only a name, a list of names, or _all can be inputted. Is this capability documented for some underlying routine used by esttab?

          Comment


          • #6
            Have a look at the "encyclopaedia": http://repec.sowi.unibe.ch/stata/estout/

            The link is at the top right hand corner of the -esttab- help-file, along with Also See links

            Comment


            • #7
              Oddly, I still don't see this capacity made obvious. But in any case, I am *very* glad to know it exists, because esstab is so easy to work with when outputting latex files. (On the other hand, when instead outputting .rtf --- which I am currently doing because JHR refuses to publish ultimate latex files, what a pain --- it's hugely painful because it's difficult to know which options are valid for rtf.) Anyway, serious thanks to you both!

              Comment


              • #8
                Have a look at the following link under "Other"

                http://repec.org/bocode/e/estout/advanced.html

                All the options should work except maybe how equations are rendered. I am no expert in writing equations in MS Word, I only do it if my coauthors insist on it. You may have to do this manually after creating the matrices.

                Comment

                Working...
                X