I want to produce a LaTeX table which has means by group and then t-tests of the differences. Like this:
This feels like something that should be easy but I'm not finding it so. In this post Chuck Huber (StataCorp) outlines how to do this elegantly for tests between variables using table (command) (result) but that doesn't work if I want to include an if statement to test within a given variable. In this post https://www.statalist.org/forums/for...-test-to-latex @Andrew Musau outlines a solution using expand and esttab. But, this will be slow given my dataset is large and I need to because of the large number of comparisons I need to formulate and the number of reported observations will be wrong, etc. Is there any way to do this? I would especially like to find a way of doing it without using packages from ssc as I am working on a server which doesn't allow them to be quickly installed.
I tried something ugly like this:
and so on for a large number of groups. But this doesn't work. Thanks as always for any bright ideas. Stu.
mean (exp_a) | mean exp_b | diff | p-value | |
All | ||||
MBC=0 | ||||
MBC=1 | ||||
LKZ=0 | ||||
LKZ=1 | ||||
MBC |
I tried something ugly like this:
Code:
collect clear local fortable "exp_a =r(mu_1) exp_b=r(mu_2) Diff=(r(mu_2)-r(mu_1)) pvalue=r(p): ttest exp_a=exp_b" table (command) (result), command(`fortable') preserve keep if mbc==0 table (command) (result) , command(`fortable') append restore preserve keep if mbc==1 table (command) (result) , command(`fortable') append restore
Comment