无法导出统计图和 table
Fail to exporting stata graph and table
我在 Ubuntu 系统下用脚本代码编写 Stata do-file 和 运行 它。
具有以下内容的 code.sh 文件:
#!/bin/bash
stata < mydofile.do > run.log
mydofile.do 使用以下代码:
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" ))
我 运行 code.sh 但无法导出图形和 table。我的问题是如何解决此问题以获得 Fig1.png 和 Table1.rtf?
日志文件
___ ____ ____ ____ ____ (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);
我认为 estout/esttab 问题可能是由于 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.
我不确定这个版本的 Stata 是否支持在 Linux 上以批处理模式导出 png 图形。尝试导出为 eps,或将它们保存为 gph,如果可能的话,然后在您重新登录时进行转换(图形使用 gph 文件,然后在 GUI 或什至控制台版本中导出)。您也可以使用 imagemagick
等命令行工具将 eps 转换为 png。您可以从 Stata 中 shell 在您的 do-file 中执行此操作。
不幸的是,我无法使用装有 Stata 的 Linux 机器来测试这些理论,因此请报告这是否对您有用。
我在 Ubuntu 系统下用脚本代码编写 Stata do-file 和 运行 它。
具有以下内容的 code.sh 文件:
#!/bin/bash
stata < mydofile.do > run.log
mydofile.do 使用以下代码:
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" ))
我 运行 code.sh 但无法导出图形和 table。我的问题是如何解决此问题以获得 Fig1.png 和 Table1.rtf?
日志文件
___ ____ ____ ____ ____ (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);
我认为 estout/esttab 问题可能是由于 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.
我不确定这个版本的 Stata 是否支持在 Linux 上以批处理模式导出 png 图形。尝试导出为 eps,或将它们保存为 gph,如果可能的话,然后在您重新登录时进行转换(图形使用 gph 文件,然后在 GUI 或什至控制台版本中导出)。您也可以使用 imagemagick
等命令行工具将 eps 转换为 png。您可以从 Stata 中 shell 在您的 do-file 中执行此操作。
不幸的是,我无法使用装有 Stata 的 Linux 机器来测试这些理论,因此请报告这是否对您有用。