benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
70 stars 17 forks source link

Issues with {char} directives in SMCL output #48

Open NilsEnevoldsen opened 2 years ago

NilsEnevoldsen commented 2 years ago

Two related issues with {char} directives in SMCL output:

  1. {char} directives can be truncated, illustrated by the first and third tables below
  2. {char} directives are treated as a multiple characters for the purpose of column alignment, illustrated by the second and fourth tables below

Example:

clear all
sysuse auto
lab var displacement "Displacement (in{char 179})"
qui reg price displacement
estout ., nobase noomit label
estout ., nobase noomit label varwidth(30)
qui reg price c.weight##i.foreign
estout ., nobase noomit label interaction(" {char 215} ")
estout ., nobase noomit label interaction(" {char 215} ") varwidth(36)

Example result:

. clear all

. sysuse auto
(1978 Automobile Data)

. lab var displacement "Displacement (in{char 179})"

. qui reg price displacement

. estout ., nobase noomit label

---------------------------------
                                .
                                b
---------------------------------
Displacement (in{c~)     15.89588
_cons                    3029.042
---------------------------------

. estout ., nobase noomit label varwidth(30)

-------------------------------------------
                                          .
                                          b
-------------------------------------------
Displacement (in³)        15.89588
_cons                              3029.042
-------------------------------------------

. qui reg price c.weight##i.foreign

. estout ., nobase noomit label interaction(" {char 215} ")

---------------------------------
                                .
                                b
---------------------------------
Weight (lbs.)            2.994814
Foreign                 -2171.597
Foreign {char..)         2.367227
_cons                   -3861.719
---------------------------------

. estout ., nobase noomit label interaction(" {char 215} ") varwidth(36)

-------------------------------------------------
                                                .
                                                b
-------------------------------------------------
Weight (lbs.)                            2.994814
Foreign                                 -2171.597
Foreign × Weight (lbs.)         2.367227
_cons                                   -3861.719
-------------------------------------------------

As an aside, you might consider making {char 215} the default interaction for SMCL output, but I wouldn't do that unless these issues were fixed.

benjann commented 2 years ago

Hi Nils, truncation could be prevented by typing noabbrev but this would not solve the misalignment issue. I'll try to think about this but cannot make any promises. I believe quite radical changes in how the SMCL code is written would be necessary. ben

NilsEnevoldsen commented 2 years ago

truncation could be prevented by typing noabbrev but this would not solve the misalignment issue.

True, but it's also possible to want truncation (it is the default, after all) without wanting it to occur in the middle of a char directive.

I'll try to think about this but cannot make any promises.

Understood, and this issue is not a priority for me personally. It would be more important if it affected an output format that was often used as a publishable product.