Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display mean by group for multiple variables in columns next to each other

    Hello,

    I want to get a basic overview of my sample. For this I want to compare the means for multiple variables for different sub-groups of my sample. For example, I want to compare the mean across income categories, gender, HHs with and without children etc.

    This is an extract of my data

    Code:
    clear
    input float(hh_adults hh_child hh_size hh_employed max_educ)
    3 4 7 1  6
    2 1 3 1  5
    2 0 2 0  4
    1 1 2 0  5
    4 0 4 1 11
    2 0 2 1  3
    1 0 1 0 11
    3 1 4 1  3
    2 0 2 0  6
    2 2 4 2  6
    4 0 4 1 11
    3 1 4 0  4
    3 1 4 2  4
    2 0 2 1  4
    5 0 5 2  5
    1 0 1 0 11
    3 2 5 2  4
    4 1 5 1  6
    4 1 5 1  3
    5 0 5 3  3
    2 1 3 1  4
    1 1 2 1  4
    5 0 5 3  3
    3 0 3 1  4
    3 0 3 0  3
    3 0 3 1  4
    3 3 6 1  4
    2 0 2 0  7
    2 0 2 0  5
    2 0 2 1  3
    2 1 3 0  3
    1 0 1 1  5
    2 2 4 2 11
    1 0 1 1  3
    3 1 4 1  3
    3 2 5 1  5
    2 0 2 2  5
    2 2 4 2  5
    3 1 4 2  4
    3 0 3 2  6
    3 1 4 2  5
    2 2 4 1  8
    2 1 3 0  7
    3 3 6 1  3
    2 0 2 0  3
    2 1 3 1  6
    1 1 2 1  6
    2 1 3 0  3
    2 0 2 1  4
    3 0 3 3  4
    2 2 4 1  7
    3 2 5 2  6
    1 0 1 1  3
    1 2 3 0  6
    2 2 4 2  6
    2 0 2 1  4
    3 1 4 2 11
    1 0 1 1  5
    2 2 4 1  6
    6 1 7 2  3
    2 2 4 0 11
    2 0 2 0  3
    2 0 2 0 11
    3 1 4 1  3
    2 0 2 1  3
    2 1 3 1  6
    2 1 3 2 11
    1 2 3 1  8
    4 1 5 1  5
    2 1 3 2  6
    1 0 1 0  4
    2 0 2 2  3
    4 0 4 1  6
    1 3 4 0  6
    3 2 5 3 11
    4 0 4 1  3
    3 1 4 1  3
    3 2 5 3  5
    3 0 3 1  3
    4 2 6 2  4
    3 0 3 1  6
    1 1 2 1  6
    6 0 6 4  3
    3 0 3 3  4
    3 0 3 2  3
    4 0 4 2  3
    3 0 3 0 11
    2 0 2 1  4
    2 1 3 0  5
    2 2 4 1  5
    2 4 6 0  5
    3 2 5 2  8
    2 2 4 2  4
    3 0 3 0  5
    6 1 7 1 11
    2 1 3 1  5
    2 0 2 1  3
    4 0 4 2  6
    3 0 3 2  5
    3 0 3 1  3
    end
    label values max_educ education
    label def education 3 "Some Years of Primary School", modify
    label def education 4 "All Primary School", modify
    label def education 5 "Some years of Secondary School", modify
    label def education 6 "All Secondary School", modify
    label def education 7 "Technical or Technological Incomplete", modify
    label def education 8 "Technical or Technological Complete", modify
    label def education 11 "None", modify
    This command basically gives me what I want. The problem is the display. The different categories are listed below each other, however, for an easier overview and comparison I want them to be displayed next to each other with different columns for each category.

    Code:
    estpost tabstat hh_adults hh_child hh_size hh_employed max_educ , by(income_cat) c(stat) stat(mean)
    esttab, cells("mean")
    estout, cells("mean")
    esttab using stats_income, replace cells("mean(fmt(2))") nonumber nomtitle ///
            noobs label booktabs collabels("Mean") title(Summary Statistics - Income Categories)
    Lastly, I want to export it to Latex. The command I am using so far does this already. If I need to use another one, that should be possible as well at best.

    Thank you!

  • #2
    Code:
    dtable c.(hh_adults hh_child hh_size hh_employed), by(max_educ, nototals)
    collect export my_results_file.tex, replace
    N.B. Requires version 18.

    Comment


    • #3
      This is perfect and does exactly what I want! Luckily, I just upgraded to Stata 18.

      Thanks Clyde!

      Comment

      Working...
      X