I'm currently working with Stata to write my bachelor thesis, and I've encountered a problem with formatting table 1 (descriptive statistics) I can't seem to solve.
I'm researching the effects of concurrent European and local elections on local voter turnout in Germany across federal states since 1979. For table 1, I would like to include the mean of local voter turnout ('kw_beteiligung') in each state + total, and the frequencies and percentages of the dummy variables 'ost' (whether a state is former Eastern or Western Germany or not) and 'zeitgl_ew' (whether the local election is simultaneous to an European election).
I've been able to compute everything that I wanted using dtable and collect. However, the contents of my table are a bit unclear, because the contents in each cell are aligned and displayed differently. For example, sometimes the mean and sd is in one row, sometimes it's in two, so it looks confusing. I would like to force stata to have two rows (e.g. one for mean and one for sd / one for frequency and one for percentage), or alternatively to put it all in one row. (Because the names of the federal states differ in length quite a bit, the widths of the columns do as well.)
This is my dtable + collect command so far:
dtable kw_beteiligung i.ost i.zeitgl_ew, by(BL, tests) varlabel ///
factor(ost zeitgl_ew, test(none)) ///
sample(, statistics(freq) place(seplabels)) ///
sformat("(N=%s)" frequency) ///
note(Gesamtzahl Beobachtungen: N = 104) ///
note(Quelle: Eigene Recherchen auf den Websiten der Statistischen Landesämter, des Statistischen Bundesamts und der Bundes-/Landeswahlleiter:innen) ///
column(by(hide)) ///
nformat(%5.2f mean sd) ///
title(Tabelle 1. Deskriptive Statistik)
collect style title, font(,bold)
collect style header, title(label) level(label)
collect style row stack, nobinder
collect style cell var[kw_beteiligung 1.ost 1.zeitgl_ew], border(bottom, pattern(single)
collect export table1.html, replace
Which gets me the table that I added.Table1
Furthermore, I tried computing my table directly with collect, which to my understanding does not work, because I want to have one table and not multiple.
I also tried the table command below, which does not work, because "factor variable ost conflicts with dimension of the same name, r(459)"
table (kw_beteiligung ost zeitgl_ew) (BL), ///
statistic(mean kw_beteiligung) statistic(sd kw_beteiligung) ///
statistic(fvfrequency ost) statistic(fvpercent ost) ///
statistic(fvfrequency zeitgl_ew) statistic(fvpercent zeitgl_ew) ///
nformat(%6.2f mean sd)
Other commands I know that put cell content in two rows do not work with collect.
To solve this problem would enhance my layout by quite a bit.