Announcement

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

  • Problems with Outreg2 for my dissertation

    Hello, I am having some problems running my code in stata. The code is as follows:

    regress dependent var1 if Indicator2==1
    outreg2 using Hypothesis_1, pvalue replace excel sideway noparen e(r2_a) title(Loyaly Norm vs. Systemic Repression) cttop(OLS Binary, Unrestricted Universe)
    quietly margins, at(var1=(0(.1)1)) atmeans vsquish post
    marginsplot, recast(line) recastci(rarea) ti(Loyaly Norm vs. Systemic Repression) subtitle("OLS Binary, Unrestricted Universe")
    graph save dependent_var1_Hypoth1A_OLSBinaryUnrestrictedUniv
    graph export dependent_var1_Hypoth1A_OLSBinaryUnrestrictedUniv. png, width(800) height(600)
    putexcel set Hypothesis_1, modify
    putexcel A30=image(dependent_var1_Hypoth1A_OLSBinaryUnrestr ictedUniv.png)

    Rather than creating an excel document entitled Hypothesis_1 and then appending my graphs on A30 of the same excel graph, the outreg2 portion of the code generates an XML file with my regression results at the top and the putexcel portion creates an XLS file with a graph starting on A30. I've tried converting the XML file to XLS using the outreg code or after, but the file is corrupted. The result is my regression is stuck in one file and my graph is in my xls file. I could just use putexcel to construct the regression model, but I like out outreg2 formats the regression results, and I want to line up about eight models next to eachother---outreg2 would create a chart that's easily readable.

    At this point, I'm leaning towards just pasting in the graphs, but I have hundreds of models to run for my analysis, so that's going to be really annoying and waste a bunch of time i don't really have. Any advice you can provide would be super helpful.

    I would provide my data--but my dataset is huge. If necessary, I can just cut a couple of variables for you guys to use if someone needs data to look at this.
    Thank you,
    Maeryn

  • #2
    Perhaps if you specified
    Code:
    outreg2 using Hypothesis_1.xls, ... excel ...
    outreg2 would create a file in xls format rather than xml format. Since the description of the excel option in the help outreg2 output is

    excel specifies an xml, xls, xlm, or cvs file compatible with a standard spreadsheet like MS Excel.
    I'm guessing xml is the default if you don't specify otherwise.

    Comment


    • #3
      No, I take that back. When I tried to duplicate your problem with the following reproducible example (the problem is not at all dependent on your data so there was no reason not to provide an example of your problem using a standard Stata dataset)
      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . quietly regress price length if foreign==0
      
      . outreg2 using "~/Downloads/or.xls", pvalue replace excel sideway noparen e(r2_a) title(Whatever)
      ~/Downloads/or.xls
      dir : seeout
      
      . scatter price length
      
      . graph export "~/Downloads/or.png", width(800) height(600) replace
      (file ~/Downloads/or.png written in PNG format)
      
      . putexcel set "~/Downloads/or.xls", modify
      
      . putexcel A30=image("~/Downloads/or.png")
      workbook /Users/lisowskiw/Downloads/or.xls could not be loaded
      r(603);
      When I use Excel to open or.xls it throws a dialog box indicating problems

      Click image for larger version

Name:	p1.png
Views:	1
Size:	45.2 KB
ID:	1564227


      but when I let it open the file the results look fine.

      Click image for larger version

Name:	p2.png
Views:	1
Size:	54.2 KB
ID:	1564228


      It appears that outreg2 is incorrectly writing xml into a file with an xls suffix (a comparison found no differences between an xls and a xml dataset produced with this code), which stops Stata cold and even looks wrong to Excel. There is no obvious way to get outreg2 to produce an xls workbook.

      If you use Stata to create and save .xml workbooks and your png graphs, then manually open each xml workbook and save it as .xls, you could then run a second Stata program to paste the graphs into the appropriate workbooks.

      Comment

      Working...
      X