Here is an MWE with the good old car dataset. I loop over two outcomes as the issue occurs only with multiple columns
Code:
sysuse auto.dta
global outcomes price mpg
global X weight length
local n_outcomes : word count $outcomes
forval i = 1/`n_outcomes' {
local Y `: word `i' of $outcomes'
local outcome_`i' = "`Y'"
reg `Y' $X
mat result = r(table)
scalar b_`i' = result[1,1]
scalar SE_`i' = result[1,2]
scalar p_`i' = result[1,4]
local sig_`i' = ""
if p_`i' <= 0.1 {
local sig_`i' = "*"
}
if p_`i' <= 0.05 {
local sig_`i' = "**"
}
if p_`i' <= 0.01 {
local sig_`i' = "***"
}
}
* Table
capture file close sampleTable
file open sampleTable using "sample.tex", write replace
file write sampleTable ///
"\begin{tabular}{lc}" _n ///
"\hline \hline \\ [-1.8ex]" _n ///
" & `outcome_1' & `outcome_2' \\" _n ///
"\hline \\ [-1.8ex]" _n ///
" &" %9.3f (b_1) "`sig_1' & " %9.3f (b_2) "`sig_2' \\" _n ///
" & ("%9.3f (SE_1) ") & (" %9.3f (SE_2) ") \\" _n ///
"\hline\hline" _n ///
"\end{tabular}"
file close sampleTableThe problem is that the formatting part %9.3f adds a space in the final .tex file (see below) which is annoying if I have to change that manually. Any suggestion how I can change this within the do-file?
Code:
\begin{tabular}{lc}
\hline \hline \\ [-1.8ex]
& price & mpg \\
\hline \\ [-1.8ex]
& 4.699*** & -0.004*** \\
& ( -97.960) & ( -0.080) \\
\hline\hline
\end{tabular}
0 Response to Format regression coefficients using file write
Post a Comment