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

Double backlashes are converted to single backslash in -estpost tabulate- equation label #3

Closed NilsEnevoldsen closed 9 years ago

NilsEnevoldsen commented 9 years ago

Input:

sysuse auto, clear
lab def origin 0 "Type: dome\\stic" 1 "Type: fore\\ign", modify
lab def rep78 1 "Rep. rec. 1" 2 "Rep. rec. 2" 3 "Rep. rec. 3" 4 "Rep. rec. 4" 5 "Rep. rec. 5"
lab val rep78 rep78
estpost tabulate rep78 foreign
esttab, cell(colpct(fmt(2))) unstack noobs modelwidth(15) varlabels(`e(labels)') eqlabels(`e(eqlabels)')

Expected result:

------------------------------------------------------------
                         (1)                                

             Type: dome\\s~c Type: fore\\ign           Total
                      colpct          colpct          colpct
------------------------------------------------------------
Rep. rec. 1             4.17            0.00            2.90
Rep. rec. 2            16.67            0.00           11.59
Rep. rec. 3            56.25           14.29           43.48
Rep. rec. 4            18.75           42.86           26.09
Rep. rec. 5             4.17           42.86           15.94
Total                 100.00          100.00          100.00
------------------------------------------------------------

Actual result:

------------------------------------------------------------
                         (1)                                

             Type: dome\stic  Type: fore\ign           Total
                      colpct          colpct          colpct
------------------------------------------------------------
Rep. rec. 1             4.17            0.00            2.90
Rep. rec. 2            16.67            0.00           11.59
Rep. rec. 3            56.25           14.29           43.48
Rep. rec. 4            18.75           42.86           26.09
Rep. rec. 5             4.17           42.86           15.94
Total                 100.00          100.00          100.00
------------------------------------------------------------

Possible fix:

Bump version of _estpost_eqnamesandlabels and estpost_tabulate* from 8.2 to >=9.0. There might be analogous problems with subroutines other than tabulate or with _estpost_namesandlabels that would also be fixed by this bump, but I haven't checked them.

NilsEnevoldsen commented 9 years ago

I think this is the minimum necessary to fix this particular issue, but it might be worthwhile to bump the other programs as well.

benjann commented 9 years ago

(I would prefer to retain support for version 8.2.) The reason why \ gets stripped is that Stata thinks one of the \ is an escape character to delay macro expansion. In estout.ado I tried to be consistent and always work with macval() to prevent such problems. A similar approach could be followed in estpost.ado.

benjann commented 9 years ago

If the desired output is LaTeX, maybe simple use \newline instead of .

benjann commented 9 years ago

Oh, interesting, markdown also kills the double backslash.

NilsEnevoldsen commented 9 years ago

Ah. But other programs, like estpost_stci, are already version 9.2.

Would you accept a pull request that uses macval()s instead?

NilsEnevoldsen commented 9 years ago

You can wrap code in backticks: \\.

NilsEnevoldsen commented 9 years ago

\newline doesn't work in this particular instance (\shortstack{}), unfortunately.

benjann commented 9 years ago

Some of the estpost subroutines require Stata 9 (indicated in the helpfile, but not very prominently) as they are based on stuff that's not available in Stata 8. But in general, estpost still supports Stata 8.

NilsEnevoldsen commented 9 years ago

Got it.

Would you accept a pull request that uses macval()s instead?

benjann commented 9 years ago

Sure. But note: I'm not using github in the way you're supposed to. I keep my own master version of estout that is not connected to github. When I change stuff, I change it on my computer. Once in a while, when I send an estout update to SSC, I push the new version to github. So it doesn't really matter whether I accept a pull request on github because it will get lost with the next update anyway. (Why is it called "pull request" by the way, I find the github slang quite confusing.) If a suggestion makes sense to me, however, I will add it to my private version of estout so that it will appear in the next update. I'll also try to accept the pull request on github so that you know I saw your suggestion and made changes to estout accordingly (although the changes I actually do might not be identical to the suggested changes).

NilsEnevoldsen commented 9 years ago

I see. No problem. A pull request is still probably the easiest way to show you the suggested changes, so I'll continue to do that.

A note about terminology. In order to suggest a change to estout, I:

  1. fork (i.e. copy) your entire estout git repository (i.e. project), then
  2. make commits (i.e. changes) to my forked repository, then
  3. request that you pull those commits from my repository into your own repository.
sergiocorreia commented 9 years ago

We're all still a bit confused by this, but the reason is probably:

Pushing to a remote means pushing code changes from your local code repository (your computer) to a remote repository. But I can't push code to your repo, so instead I request you to pull those changes.

Edit: Nils beat me to it.

benjann commented 9 years ago

I see, makes sense.

NilsEnevoldsen commented 9 years ago

Here's a version that uses -macval()- instead. I kept the scope narrow. I don't know if eqnames needs similar treatment to eqlabels, for example. The single change to estpost_tabulate_twoway should probably also be made to estpost_tabulate_oneway.

benjann commented 9 years ago

I now uploaded an update that implements the macval() approach. It also affects estpost svy:tablulate and estpost stci. The commands estpost tabstat, estpost tabulate, estpost svy:tabulate, and estpost stci now also have a new elabel option to enforce saving labels in e(). By default these programs use the labels as names in the stored vectors unless the labels are too long or contain certain special characters.

benjann commented 9 years ago

Made some more changes to improve support of labeled by() variables in estpost tabstat.

NilsEnevoldsen commented 9 years ago

:+1: