I have a very particular format of tables for which I need to fill in statistics, and my current goal is to get as close to this format as possible using Stata17's table command functionality.

I will use the auto.dta dataset to illustrate my situation.

Below is the current code and output I have.

. table rep78 foreign, stat(freq) stat(perc, across(rep78)) nformat(%9.0fc) sformat("%s%%" percent) missing total(foreign) name(new_coll) replace

----------------------------------------
| Car origin
| Domestic Foreign
-------------------+--------------------
Repair record 1978 |
1 |
Frequency | 2
Percent | 4%
2 |
Frequency | 8
Percent | 15%
3 |
Frequency | 27 3
Percent | 52% 14%
4 |
Frequency | 9 9
Percent | 17% 41%
5 |
Frequency | 2 9
Percent | 4% 41%
. |
Frequency | 4 1
Percent | 8% 5%
Total |
Frequency | 52 22
Percent | 100% 100%
----------------------------------------




I want the table to look like the one below essentially. I copied it from Word so I am hoping the formatting isn't terribly distorted. Basically, I want each value of the row variable to have exactly one row, so there are 4 columns with data for each row. Does anyone know how I would be able to achieve this?

Repair Record 1978 Domestic Foreign
# % # %
1 % %
2 % %
3 % %
4 % %
5 % %
Missing % %
Total 100% 100%