For regression output, I usually use a combination of eststo
to store estimations, estadd
to add the R2 and additional tests, then estab
to output the lot.
I need to do the same with the table
command. I need the mean, median and N for a variable across three by variables
and would like to add stars for the result of a ttest==1 on the mean and signtest==1 on the median. I have three by variables
, so I've been using table
to collate the mean, median and N, which I'm calling like the following pseudo-code:
sysuse auto,clear
table foreign rep78 , ///
contents(mean price median price n price) format(%9.2f)
ttest price==1, by(foreign rep78)
signtest price=1, by(foreign rep78)
I've tried esttab
and estpost
to no avail. I've also looked at tabstat
, tablemat
and summarize
as alternatives to table
, but they don't allow three by variables
.
How can I create this table, add the stars for the ttest
and signtest
p-values and output the full table?
The main point in your question seems to be producing a LaTeX table. However, you show "pseudo-code", that looks pretty much like Stata code, with the caveat that it is illegal.
In particular, for the ttest
you can only have one variable in the by()
option. But notice that ttest
allows also the by:
prefix (you can use both, in fact). Their reasons-to-be are different. On the other hand, signtest
does not allow a by()
option but it does allow the by:
prefix. So you should probably clarify what you want to do before creating the table.
If you are trying to use the by:
prefix in both cases and afterwards produce a table, you can create a grouping variable, and put the commands in a loop. In this way, you can try tabulating the saved results for each group using the ESTOUT module (by Ben Jann in SSC). Something like:
*clear all
set more off
sysuse auto
keep price foreign rep78
* create group variable
egen grou = group(foreign rep78)
* tests by group
forvalues i = 1/8 {
ttest price == 1 if grou == `i'
signtest price = 1 if grou == `i'
*<complete with estout syntax>
}
See help by
, help egen
(the group function), help estout
and help saved results
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.