简体   繁体   中英

Fail to exporting stata graph and table

I write the Stata do-file and run it with a script code under the Ubuntu system.

The code.sh file with the following contents:

#!/bin/bash
stata < mydofile.do > run.log

mydofile.do with the following code:

reghdfe y x, absorb( id year ) vce(cluster id )  
eststo model1    
esttab model1 using Table1.rtf, replace 
twoway (scatter y x)  
esttab model1 using "Table/Table1.rtf",replace  ///
stats(CityFixed TimeFixed N r2 , labels("city FE" "year FE" "N" "R2" ))

I run the code.sh but fail to export graph and table. My question is how to fix this problem to get Fig1.png and Table1.rtf?

The log file

  ___  ____  ____  ____  ____ (R)
 /__    /   ____/   /   ____/
___/   /   /___/   /   /___/   14.1   Copyright 1985-2015 StataCorp LP
  Statistics/Data Analysis            StataCorp
                                      4905 Lakeway Drive
                                      College Station, Texas 77845 USA
                                      800-STATA-PC        http://www.stata.com
                                      979-696-4600        stata@stata.com
                                      979-696-4601 (fax)

Single-user Stata perpetual license:
       Serial number:  
         Licensed to:  
                       

Notes:
      1.  Stata is running in batch mode.
      2.  Unicode is supported; see help unicode_advice.


.   set more off 

.   use "Data/yearbook1999-2018.dta", clear

.   
.   reghdfe y x, absorb( id year ) vce(cluster id )
(dropped 5 singleton observations)
(MWFE estimator converged in 5 iterations)

HDFE Linear regression                            Number of obs   =      5,258
Absorbing 2 HDFE groups                           F(   1,    294) =      12.50
Statistics robust to heteroskedasticity           Prob > F        =     0.0005
                                                  R-squared       =     0.9668
                                                  Adj R-squared   =     0.9647
                                                  Within R-sq.    =     0.0120
Number of clusters (id)      =        295         Root MSE        =     0.1867

                                   (Std. Err. adjusted for 295 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       y     |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       x     |   .0298449   .0084422     3.54   0.000     .0132302    .0464597
       _cons |   18.07378   .0315133   573.53   0.000     18.01176     18.1358
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          id |       295         295           0    *|
        year |        19           0          19     |
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

.   eststo model1
.   
.   esttab model1 using "Table/Table1.rtf",replace ///
. stats(CityFixed TimeFixed N r2 , labels("city FE" "year FE" "N" "R2" ))
command stats is unrecognized
r(199);


. twoway (scatter y x) 

. graph export Figure/Fig1.png, replace
translator Graph2png not found
r(111);

I think the estout/esttab issue is probably due to how Stata deals with delimiters/comments in batch mode with redirection . The way you launched the job, Stata does not know the commands it receives come from a file. As far as Stata is concerned, it is as if you are typing every command in mydofile.do on the Stata command line. Like all comments indicators, /// does not work interactively. Try putting all the code on one line without /// or else start the job nohup stata -b do mydofile.do & . This will route the output to mydofile.log in your directory where you started the job from. This is the recommended way to do batch jobs. Read more about it in the GSU manual .

I am not sure if this version of Stata supports png graphics exports on Linux in batch mode. Try exporting as eps, or saving them as gph, and then converting when you log back in if that is possible (graph use the gph file and then export in the GUI or maybe even console version). You may also be able to convert eps to png using command line tools like imagemagick . You can shell out from within Stata to do that in your do-file.

Unfortunately I don't have access to a Linux machine with Stata on it to test these theories, so please report back whether any of this worked for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM