Announcement

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

  • File write characters removed.

    I am still outputting non-standard tables to TeX and using file write following this example: https://github.com/worldbank/stata-t...o/filewrite.do. Here is a similar MWE as in a previous thread.

    Code:
    cap erase "sample.tex"
    
    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}{lcc}"                                                                                                _n ///
        "\hline \hline \\ [-1.8ex]"                                                                                          _n ///
        " & `outcome_1' & `outcome_2' \\"                                                                                     _n ///
        "\hline \\ [-1.8ex]"                                                                                                   _n ///
            " $Y_0$ &" %9.3f (b_1) "`sig_1' & " %9.3f (b_2) "`sig_2' \\"                                                       _n ///
            " $Y_0$ & (" "`=string(SE_1, "%15.3f")'" ") & ("  "`=string(SE_2, "%15.3f")'" ") \\"                              _n ///
        "\hline\hline"                                                                                                       _n ///
        "\end{tabular}"
    file close sampleTable
    The problem is witht the $Y_0$. For some obscure reason the $Y_0 is removed from the tex file and just the $ is reported. See below.

    Code:
    \begin{tabular}{lcc}
    
    \hline \hline \\ [-1.8ex]
    & price & mpg \\
    \hline \\ [-1.8ex]
    $ & 4.699 & -0.004 \\
    $ & (-97.960) & (-0.080) \\
    \hline\hline
    \end{tabular}
    Does Stata somehow have problems with underscores or dollar signs?
    Last edited by Henry Strawforrd; 08 Mar 2022, 14:12.

  • #2
    Stata doesn't have a problem with dollar signs or underscores. Stata uses dollar signs to indicate global macros. See the output of help macro.
    Code:
    . display "$Y_0$"
    $
    
    . global Y_0 hello
    
    . display "$Y_0$"
    hello$
    
    . display "\$Y_0$"
    $Y_0$

    Comment

    Working...
    X