Announcement

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

  • Looking for alternatives to outreg2

    Dear Statalist,

    I am trying to do some descriptives and to export the table to a word document. I usually use outreg2 command, however, it seems that is not properly working (I am using Stata 15.1). This is the command I am trying
    Code:
    bys offshoring: outreg2 using "firm_descriptives.doc" ,  sum(log) eqkeep(mean sd N) keep(offshoring coopera internalRD )
    invalid syntax
    r(198);
    I am pretty sure this command has worked in the past. I am also interested in reporting another descriptive but this time for the panel structure: xtsum...

    Have anyone any idea of what am I doing wrong with the outreg2 command; or any other command that allow me to export those descriptive to Word?

    Any help will be much appreciated.

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    I've never done outreg2 with a bysort statement. I don't know how that would make sense. outreg2 works from a set of results so sorting data seems irrelevant. If you search this listserve, you'll find many alternative to outreg2. There are also Stata provided procedures that handle formatted output as well.

    Comment


    • #3
      Dear Phil,

      Thanks for your answer, the fact is that I need to do a summary for some variables for the two categories of the offshoring (dummy). I have used the above outreg2 command in the past, but now it give that error. The point is that even dropping the "bys offshoring:" the command still does not work.
      I have tried then with the tabout command, but it also give me some problems since the tables are not good enough when exported to Word, for instance:
      Code:
      sysuse voter, clear
      
      . tabout inc candidat using table9.doc, replace c(mean pfrac) f(1) clab(%) sum
      
      Table output written to: table9.doc
      
              Candidate voted for, 1992                       
      Family Income   Clinton Bush    Perot   Total
              %       %       %       %
      <$15k   8.3     3.2     2.5     4.7
      $15-30k 10.8    8.4     4.8     8.0
      $30-50k 12.3    11.4    6.3     10.0
      $50-75k 8.0     8.4     3.6     6.7
      $75k+   4.7     6.2     2.1     4.3
      Total   8.8     7.5     3.9     6.7
      However, when I try my dataset it is a mess, and tables does not visualize well in the doc document.
      Code:
      tabout offshoring using table9.doc, replace c(mean coopera mean permanent mean internalRD) f(1)  sum
      
      Table output written to: table9.doc
      
      If the firm has any expenditure on external knowledge from abroad       Mean    Mean    Mean
              coopera permanent       internalRD
      0       0.4     0.8     0.0
      1       0.7     0.9     0.2
      Total   0.4     0.8     0.1
      Is there any other command I could use for doing what outreg2 should do?
      Below you may find a short example of my dataset.

      Thanks in advance.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte(offshoring coopera) double internalRD
      0 0   .09046644551097324
      0 0   .20395702599256194
      0 0   .31468851173081386
      0 0     .694693505873705
      0 0   1.4777636434095467
      0 0    1.465341156936412
      0 0   1.2855846532976578
      0 .                    0
      0 .                    0
      0 .                    0
      0 0                    0
      0 0                    0
      0 0  .057618833395396696
      0 0                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 0  .023363215803786804
      0 0   .02488418510019133
      0 0   .02203491203379804
      0 0   .02197197542778446
      0 0  .024768402432117524
      0 0  .043628161799596755
      0 0  .047617787730093966
      0 0                    0
      0 .                    0
      0 .                    0
      0 1                    0
      0 0                    0
      0 0                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 0                    0
      0 0   .08102188765002487
      0 0                    0
      0 0                    0
      0 0 .0037338232374995446
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 0                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      1 1  .020868634055714878
      1 1     .022795597436482
      1 1  .012718997364693722
      1 1  .008183939809835146
      1 1   .01709749583382931
      1 1   .01871897821983031
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 0                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 .                    0
      0 0                    0
      0 0                    0
      0 1 .0018229018568699268
      0 1 .0020511170912157536
      0 1 .0022615752770694096
      0 0                    0
      0 .                    0
      0 .                    0
      0 .                    0
      end

      Comment


      • #4
        Thank you for the example of your data. I'm not a user of outreg2, and I'll admit to being unaware of the features of it you are making use of. When I read your example data from post #3 and run
        Code:
        bys offshoring: outreg2 using "firm_descriptives.doc" ,  sum(log) eqkeep(mean sd N) keep(offshoring coopera internalRD )
        it works with no syntax error from my newly-installed copy of outreg2
        Code:
        . which outreg2.ado
        /Users/lisowskiw/Library/Application Support/Stata/ado/plus/o/outreg2.ado
        *! outreg2 2.3.2  17aug2014 by [email protected]
        *! based on outreg 3.0.6/4.0.0 by [email protected]
        on my up-to-date copy of Stata
        Code:
        . about
        
        Stata/SE 15.1 for Mac (64-bit Intel)
        Revision 20 Feb 2019
        and produces the following rather nice Word document.
        Click image for larger version

Name:	outreg2 view.png
Views:	1
Size:	46.8 KB
ID:	1488341
        Does the command fail for you when applied to the data in post #3? If so, then we can rule out that your problem is somehow dependent on the data, which in any event seems unlikely,
        Last edited by William Lisowski; 15 Mar 2019, 10:54.

        Comment


        • #5
          Dear William,

          Thanks a lot for your response. Unfortunately does not work for me when using my dataset. I will try in another computer and see what happen. Also, I re-installed the outreg2 this morning using the replace option but it continuous to give the error.
          Code:
          .         which outreg2.ado
          c:\ado\plus\o\outreg2.ado
          *! outreg2 2.3.2  17aug2014 by [email protected]
          *! based on outreg 3.0.6/4.0.0 by [email protected]
          
          . about
          
          Stata/MP 15.1 for Windows (64-bit x86-64)
          Revision 21 Nov 2017
          Which other command do you know that allow me to do something similar (apart from the tabout, that as you can see in 3 give some weird tables to me)?

          Comment


          • #6
            You should in any event update your copy of Stata 15.1 to the current update level - you are at 21 Nov 2017 and the current update is 20 Feb 2019. Type update query in the Command window to get started.

            I have no advice on commands that do what you seek, unfortunately - I don't make use of them myself. I think your real goal has to be to figure out why outreg2 is not working on your system, Your reinstallation with the replace option was a good idea. Trying it with your full dataset on someone else's system is a good idea. If your dataset is not too large, and not bedeviled with nondisclosure requirements, you could post it as an attachment here. Statalist prefers dataex for example data, so that even if you're reading Statalist on a system without Stata available (frequently an iPad in my case) you can still understand everything possible about the problem. But having done that already, attaching a .dta file would be OK.

            If it continues to fail, you may need to run the command with trace turned on so you can determine the actual command buried in the heart of outreg2 that is causing the problem.

            So I'd say let's not give up on outreg2 just yet.
            Last edited by William Lisowski; 15 Mar 2019, 13:35.

            Comment


            • #7
              The posted code works fine for me too. My guess is it will work once you update Stata. But if not there are other commands like esttab and the original outreg that you could try too.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              Stata Version: 17.0 MP (2 processor)

              EMAIL: [email protected]
              WWW: https://www3.nd.edu/~rwilliam

              Comment


              • #8
                You can also try asdoc (available on SSC) .
                Code:
                ssc install asdoc
                bys offshoring: asdoc sum coopera internalRD, stat(N mean sd) replace
                Click image for larger version

Name:	Capture2.JPG
Views:	1
Size:	49.6 KB
ID:	1488491


                To find out more on asdoc , read this short blog entry
                https://fintechprofessor.com/2018/01/31/asdoc/
                Regards
                --------------------------------------------------
                Attaullah Shah, PhD.
                Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                FinTechProfessor.com
                https://asdocx.com
                Check out my asdoc program, which sends outputs to MS Word.
                For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                Comment


                • #9
                  Dear all,

                  Many thanks for your responses, at the end I tried to keep those variables first and then use outreg2 and it worked. I cannot figure out why the command does not work with the entire set of variables (around 500 variables), which it did in the past, in fact the command is supposed to keep those variables but it continued to give that error when the whole set of variables are present.
                  I will also check esttab and asdoc as you suggest, to see if I can also do xtsum, which is a little more tricky with outreg2.

                  Comment


                  • #10
                    By coincidence, a similar problem with tabout was discussed today at https://www.statalist.org/forums/for...1488473-tabout . The conclusion there was that the "invalid syntax" message was not generated by tabout, but by a low-level subprogram within tabout that was called with invalid syntax, because of an error made by the user on their tabout command that was not detected by tabout.

                    So what does that offer to this discussion of outreg2? A little experimentation shows that, regardless of the variables specified in either the keep() option or (not shown here) as the optional list of variables, outreg2 will calculate summary statistics for every variable in the dataset.
                    Code:
                    . generate extravariable = _n
                    
                    . bys offshoring: outreg2 using "or2a.doc" ,  ///
                    >     sum(log) eqkeep(mean sd N) keep(offshoring coopera internalRD )
                    
                        Variable |        Obs        Mean    Std. Dev.       Min        Max
                    -------------+---------------------------------------------------------
                      offshoring |         94           0           0          0          0
                         coopera |         44    .0909091    .2908034          0          1
                      internalRD |         94    .0626518    .2595075          0   1.477764
                    extravaria~e |         94        47.5    27.27942          1         94
                    
                    
                    
                        Variable |        Obs        Mean    Std. Dev.       Min        Max
                    -------------+---------------------------------------------------------
                      offshoring |          6           1           0          1          1
                         coopera |          6           1           0          1          1
                      internalRD |          6    .0167306    .0054246   .0081839   .0227956
                    extravaria~e |          6        97.5    1.870829         95        100
                    So with 500 additional variables, I can imagine outreg2 is overwhelmed, and down in the bowels of the code, some low-level subprogram within outreg2 is called incorrectly, generating the invalid syntax message, referring not to the syntax of the outreg2 command, but of the low-level subprogram. As was the case with tabout, in my opinion, this is not appropriately robust code.

                    Comment


                    • #11
                      Originally posted by Attaullah Shah View Post
                      You can also try asdoc (available on SSC) .
                      Code:
                      ssc install asdoc
                      bys offshoring: asdoc sum coopera internalRD, stat(N mean sd) replace
                      [ATTACH=CONFIG]n1488491[/ATTACH]

                      To find out more on asdoc , read this short blog entry
                      https://fintechprofessor.com/2018/01/31/asdoc/
                      Attaullah Shah Please see the basetable command (ssc). It seems asdoc is not compatible for basetable, or vice versa, but it'd be a great thing it they can.

                      Comment

                      Working...
                      X