我编写了 Stata do 文件并在 Ubuntu 系统下使用脚本代码运行它。
包含以下内容的 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 但无法导出图形和表格。我的问题是如何解决这个问题以获得 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 .您启 Action 业的方式,Stata 不知道它收到的命令来自文件。就 Stata 而言,就好像您在 Stata 命令行上键入 mydofile.do 中的每个命令一样。与所有评论指标一样,///
不能交互工作。尝试将所有代码放在没有 ///
的一行上否则开始工作nohup stata -b do mydofile.do &
.这会将输出路由到您开始作业的目录中的 mydofile.log。这是执行批处理作业的推荐方法。了解更多信息 in the GSU manual .
我不确定这个版本的 Stata 是否支持在 Linux 上以批处理模式导出 png 图形。尝试导出为 eps,或将它们保存为 gph,然后在可能的情况下在重新登录时进行转换(图形使用 gph 文件,然后在 GUI 甚至控制台版本中导出)。您还可以使用命令行工具将 eps 转换为 png,例如 imagemagick
。 .您可以从 Stata 中掏出资金在您的 do-file 中执行此操作。
不幸的是,我无法使用装有 Stata 的 Linux 机器来测试这些理论,因此请报告其中任何一个是否对您有用。
关于ubuntu - 导出stata图和表失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62814740/