Hi there,
I'm trying to create a table of summary statistics, describing self-reported cigarette price (var: price), by different product characteristics, such as packaging type (var: packtype), brand producer (var: producertype), shop type, various demographics of the respondent, etc. I want to present these for four different time periods (var: round), as the columns.
I'd like to get the means, medians and standard devs of price within the population sub-groups (categories), for each of the four periods. A shortened version of what I want is the below (in reality I'd want more row variables, each with their own categories):

Note that I don't want the row variables to be interacted (combinations of categories), I just want the statistics for each category separately, and the row variables to be stacked on top of each other, in a long table.
I'm currently trying to use Stata 17's new table command with the collect and append functions, because it seems like it should be able to produce this, but I'm struggling! Here is as far as I've managed to get:
Which gives me the data I'm looking for, but in 3 separate tables, one with means, one with stdevs and one with medians. I just want them appended on top of each other. I'm sure I'm using the "result" option incorrectly. The labels, etc also don't look very nice.

Example code:
I'm trying to create a table of summary statistics, describing self-reported cigarette price (var: price), by different product characteristics, such as packaging type (var: packtype), brand producer (var: producertype), shop type, various demographics of the respondent, etc. I want to present these for four different time periods (var: round), as the columns.
I'd like to get the means, medians and standard devs of price within the population sub-groups (categories), for each of the four periods. A shortened version of what I want is the below (in reality I'd want more row variables, each with their own categories):
Note that I don't want the row variables to be interacted (combinations of categories), I just want the statistics for each category separately, and the row variables to be stacked on top of each other, in a long table.
I'm currently trying to use Stata 17's new table command with the collect and append functions, because it seems like it should be able to produce this, but I'm struggling! Here is as far as I've managed to get:
Code:
qui table packtype round, statistic(mean price) statistic(sd price) statistic(p50 price) nototals nformat(%9.2f) name(pricetab) qui table producertype round, statistic(mean price) statistic(sd price) statistic(p50 price) nototals nformat(%9.2f) name(pricetab) append collect layout (packtype producertype) (round) (result)
Which gives me the data I'm looking for, but in 3 separate tables, one with means, one with stdevs and one with medians. I just want them appended on top of each other. I'm sure I'm using the "result" option incorrectly. The labels, etc also don't look very nice.
Example code:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(packtype producertype price round) 3 0 2 4 3 0 1 4 1 0 .75 4 2 1 2.5 4 2 0 1 4 1 1 1.5 4 3 0 1 4 2 0 1 4 2 0 1 4 2 1 2.4 4 3 0 1 4 3 0 1.5 4 2 1 1.75 4 2 0 1 4 2 0 1 4 3 1 3 4 3 0 1.6666666 4 1 0 .6 4 3 . 1 4 3 0 1 4 3 0 1 4 3 1 3 4 2 0 1 4 3 1 3 4 2 1 2.6 4 3 1 2 4 3 0 1.5 4 2 0 1.2 4 2 1 2.2 4 3 1 3 4 2 1 2.2 4 2 0 2.15 4 2 1 1.9 4 2 0 .8 4 2 1 2.25 4 3 1 2 4 3 1 2 4 3 1 2.5 4 3 1 2.5 4 2 1 2.5 4 2 0 .5 4 2 0 1 4 3 1 2 4 2 0 1 4 3 1 2.5 4 2 0 .95 4 2 1 2.25 4 2 1 3 4 3 0 1 4 2 1 2.15 4 2 1 1.8 4 2 0 1 4 3 1 2.5 4 2 0 1 4 2 0 1 4 2 0 1.1 4 3 0 2 4 2 0 1 4 2 0 1 4 3 0 1.5 4 2 0 1 4 3 0 1.5 4 2 0 1 4 3 0 1.5 4 3 1 3 4 3 0 1 4 2 1 2.25 4 2 0 1.25 4 2 0 1 4 3 0 1.2 4 3 1 3 4 3 1 2 4 2 0 1.15 4 2 1 1.675 4 3 0 1.5 4 2 1 2.1 4 3 1 2.5 4 3 1 2.5 4 3 1 3 4 2 1 2.2 4 2 0 .8 4 3 0 1 4 3 0 2 4 2 1 1.45 4 3 1 2.5 4 3 0 1 4 3 1 3 4 3 0 1 4 2 0 1.15 4 2 1 1.35 4 2 0 1.25 4 3 0 1.5 4 2 1 1 4 2 0 1 4 3 1 2.5 4 3 1 3 4 2 0 1 4 3 0 1 4 3 1 3 4 3 0 1 4 end label values packtype packtype label def packtype 1 "1. Carton", modify label def packtype 2 "2. Pack", modify label def packtype 3 "3. Single", modify label values producertype mnc label def mnc 0 "0. Non-multinational", modify label def mnc 1 "1. Multinational", modify
Comment