Announcement

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

  • Summary statistics using two levels of grouping

    Hi,
    I am trying to make a summary statistics were I want to have it grouped in two levels of categories.

    My task is to look into number of cancer/not cancer cases for different groups of smoking consumption and were I want to display summary statistics (only the mean value). I have 4 different types of smokers (everyday , sometimes, former smoker and never tried smoking) and for each category I want to specify the statistics in a subgroup if people that have cancer or not. So in theory I would like to have 9 columns, 1 for variable name and 4x2 for types of smoker and cancer or not, with labeling on two levels (smoking and cancer cases). I have done the summary separate for age bellow but don“t know I can put it together in one nice table.

    I have tried o play around with table and collect get also without any success.

    Hoping someone experienced could help me!




    sum AGE_INT if SMOKE==1 & Cancer==1
    sum AGE_INT if SMOKE==1 & Cancer==0

    sum AGE_INT if SMOKE==2 & Cancer==1
    sum AGE_INT if SMOKE==2 & Cancer==0

    sum AGE_INT if SMOKE==3 & Cancer==1
    sum AGE_INT if SMOKE==3 & Cancer==0

    sum AGE_INT if SMOKE==4 & Cancer==1
    sum AGE_INT if SMOKE==4 & Cancer==0




  • #2
    Code:
    table (SMOKE) (Cancer), statistic(count AGE_INT) statistic(mean AGE_INT) statistic(sd AGE_INT) ///
        statistic(max AGE_INT) statistic(min AGE_INT) ///
        nformat(%1.0f count mean max min) nformat(%2.1f sd)
    Note: I have guessed that variable AGE_INT is an integer variable, so I have chosen to have the results, other than standard deviation, displayed with no decimal places, and the sd with 1 decimal place. If those formats are not to your liking, change them in the -nformat()- options.

    It would be better not to leave such things to guesswork. In the future, when asking for help with code, please show example data, using the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.
    Last edited by Clyde Schechter; 14 Feb 2023, 16:42.

    Comment


    • #3
      It worked! Thank you Clyde! :I will improve way of asking for help.

      Comment

      Working...
      X