Announcement

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

  • Using putexcel to export the results of a regression (the r(table))

    First time I actively use the forum, so please excuse me if You need further informations to help me with the problem.


    I'm using the putexcel function for the first time, and I can't get the function to export the row- and columnames with the matrix.

    First, I've successfully done a regression in STATA. Now the regression variables is stored in the matrix: r(table).
    E.g.
    Code:
    . matrix list r(table)
    
    r(table)[9,2]
                    X3       _cons
         b   1.0099472   .00092736
        se   .27275243   .02402299
         t   3.7027984   .03860316
    pvalue   .02078448   .97105662
        ll    .2526651  -.06577115
        ul   1.7672294   .06762588
        df           4           4
      crit   2.7764451   2.7764451
     eform           0           0
    Clearly the matrix has both rownames and columnames, now if I try to use the simple syntax:
    Code:
    . putexcel A1=matrix(r(table), names)
    names not found
    r(111);
    I get the error, apparently telling me that it has no names. As a side note, it has no issue exporting the matrix without the names.

    I have no clue what to do here other than start to hard code the variable names, but I'm gonna do a huge load of regressions which I need to export, so working around that would save me alot of work. Any help would be much appreciated.

  • #2
    Should it not be
    Code:
    putexcel A1=matrix(r(table)), names

    Comment


    • #3
      Originally posted by Eric de Souza View Post
      Should it not be
      Code:
      putexcel A1=matrix(r(table)), names
      Yup, I just tried it and so it should. the syntax as described here:
      https://www.stata.com/manuals13/pputexcel.pdf

      cell=matrix(name [, names | rownames | colnames] )

      Made it look as if it should be within the parenthesis.

      Thank you Eric!

      Comment


      • #4
        Welcome to Statalist!

        Note that the putexcel PDF documentation that, I expect, your web search directed you to is for Stata version 13. (I've often been misdirected to old versions of the PDF documentation.) I expect you are running a later version of Stata for which this syntax is no longer valid.

        The documentation for Stata version 14 at www.stata.com/manuals14/pputexcel.pdf and for the current Stata version (version 15, as of this writing) at https://www.stata.com/manuals/pputexcel.pdf show the updated syntax.

        Rather than search the web for basic Stata documentation, you're better off relying on the output of help putexcel to show you Stata's online help for the command, and by clicking the link at the top of the output you can open up the full documentation in Stata's PDF included in your Stata installation and accessible from Stata's Help menu.

        Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it.

        Comment


        • #5
          Another last thing to note is that you'll see that the matrix r(table) is the transposed version of the results you'd see on your screen, i.e. on screen your variable names are in the rows, but r(table) has them in columns. You can resolve this by assigning the transpose of r(table) to some matrix, then use putexcel on that, e.g.

          Code:
          matrix A = r(table)'
          /*Note the apostrophe after r(table)!*/
          putexcel A1 = matrix(A), names
          Finally, there are some user-written packages that do this automatically. If you run more than one regression at a time, as many of us do, you have to manually figure out which cells in the Excel sheet to put your tables in, and those can change if you change the variables. You may be better off learning a command like -estout- (Ben Jann, available on SSC). I know that command's syntax is formidable, but so is -putexcel-'s. You'd install that command from the command line, which directs your computer to search the Statistical Software Components site on the web (maintained by Boston College). Another command is -outreg2-, but I'm not familiar with it.

          Code:
          ssc install estout
          Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

          When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

          Comment

          Working...
          X