esttab:在 indicates() 之后订购 _cons

问题描述 投票:0回答:1

使用用户命令 esttab 时,我想将常量的估计值放在包含 indicates() 变量文本的行之后(是)。

sysuse auto
eststo m1: regress price weight length headroom i.foreign
esttab m1, indicate("International FE = *.foreign") order(length weight *.foreign headroom _cons)

我尝试在订单函数中包含不同版本的指示变量(例如 *.foreign、“International FE”),但似乎都不起作用。

交叉发布@Statalist

stata
1个回答
0
投票

考虑到风格约定,这对于表格布局来说是一件奇怪的事情,因此如果不分叉

estout/esttab
,这可能是不可能的,这遵守了这些约定。

但是,如果您愿意将表保存为某种文本文件,您可以编写一个 sed 脚本,将以 _cons 开头的行和下面的行移动到第一个 h 行之前。您可能可以在 Stata 中使用 Python 做同样的事情。

这是一个适用于 MacOS 版本

sed
的示例。这是 bash 脚本:

#!/bin/bash

# This script modifies a text file by cutting a block of lines starting with '_cons',
# the line above it, and the next two lines. It then inserts this block above the third
# occurrence of a line that consists solely of hyphens (e.g., '--------------------').
# A blank line is also inserted before the cut block.

# How to use the script:
# 1. Save the script to a file, e.g., 'process_file.sh'.
# 2. Make the script executable by running: chmod +x process_file.sh
# 3. Run the script by providing the filename of the text file to modify:
#    ./process_file.sh table.txt
#    Replace 'table.txt' with the actual filename you want to process.

# Ensure a filename is provided as an argument
if [ $# -eq 0 ]; then
  echo "Usage: $0 filename"
  exit 1
fi

# Assign the first argument (filename) to the variable 'filename'
filename="$1"

# Create a temporary file to store the cut lines and assign its name to 'tempfile'
tempfile=$(mktemp)

# Use sed to find the line starting with '_cons', capture it along with the next two lines,
# and store them in the temporary file
sed -n '/^_cons/{N;N;p;}' "$filename" > "$tempfile"

# Remove the '_cons' line and the next two lines from the original file
sed -i '' '/^_cons/{N;N;d;}' "$filename"

# Find the line number of the third occurrence of a line containing only hyphens (---)
# The grep command finds all such lines, then sed selects the third one, and cut extracts the line number
line_number=$(grep -n '^[-]\{3,\}$' "$filename" | sed -n '3p' | cut -d: -f1)

# Use the 'ed' text editor in silent mode to edit the file:
# - Move to the line number found above
# - Insert the contents of the temporary file one line above the third hyphen line
# - Insert a blank line before the pasted content
# - Write the changes and quit the editor
ed -s "$filename" <<EOF
$line_number
-1r $tempfile
-2i

.
w
q
EOF

# Remove the temporary file as it's no longer needed
rm "$tempfile"

# Print a message indicating the file has been successfully modified
echo "File $filename has been modified."

以下是在 Stata 中使用它的方法:

. sysuse auto
(1978 automobile data)

. eststo m1: regress price weight length headroom i.foreign

      Source |       SS           df       MS      Number of obs   =        74
-------------+----------------------------------   F(4, 69)        =     22.21
       Model |   357434897         4  89358724.3   Prob > F        =    0.0000
    Residual |   277630499        69  4023630.42   R-squared       =    0.5628
-------------+----------------------------------   Adj R-squared   =    0.5375
       Total |   635065396        73  8699525.97   Root MSE        =    2005.9

------------------------------------------------------------------------------
       price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      weight |   5.749148   .9514243     6.04   0.000     3.851108    7.647187
      length |  -81.11971   33.27376    -2.44   0.017     -147.499   -14.74036
    headroom |  -481.1805   324.0927    -1.48   0.142    -1127.728    165.3667
             |
     foreign |
    Foreign  |   3570.379   633.9009     5.63   0.000     2305.781    4834.976
       _cons |   4429.788   3720.404     1.19   0.238    -2992.214    11851.79
------------------------------------------------------------------------------

. esttab m1 using table.txt, indicate("International FE = *.foreign") order(length weight *.foreign headr
> oom _cons) replace
(output written to table.txt)

. shell ./process_files.sh table.txt

----------------------------
File table.txt has been modified.

. type table.txt
----------------------------
                      (1)   
                    price   
----------------------------
length             -81.12*  
                  (-2.44)   

weight              5.749***
                   (6.04)   

headroom           -481.2   
                  (-1.48)   

Internatio~E          Yes   

_cons              4429.8   
                   (1.19)   

----------------------------
N                      74   
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
© www.soinside.com 2019 - 2024. All rights reserved.