Announcement

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

  • Descriptive statistics for numerical and categorical variables

    Hi, I am trying to create a descriptive statistics table for numerical and categorical variables in Stata. I have read that for categorical variables you would instead report percentage or the proportion of the observations in each group. I am struggling to do this though. An example of what I am trying to replicate is below, which came from a paper
    Click image for larger version

Name:	sum.png
Views:	1
Size:	115.1 KB
ID:	1662512

    For my project, my categorical variables are mental wellbeing, age, education, employment, marital status. My numerical variables are gender, age and income. At the same time I wanted to split this between ethnic and non-ethnic people. Like in this example they split it by G1, G2, G2.5 and natives. Any help?


  • #2
    Please give your example data using the dataex command. For us to provide meaningful feedback, you must provide your example data using the dataex command, the real data from an easily importable source (i.e., Github), or the equivalent of a toy example.
    Otherwise, anything we say is simply a waste of time. Note, that I'm not trying to be mean in saying this, I'm saying this because if we can't see your dataset as you do with a minimal worked example, anything we suggest is just guesswork. The reason that I'm emphasizing this is because questions like this one likely have a relatively simple fix, but even simple fixes can be wildly overcomplicated without a minimal worked example of a dataset and code that you've tried to accomplish your task.

    So please, provide us with your example data that encapsulates the problem and I'm more than okay with helping you solve this Taiba Chau

    Comment


    • #3
      Taiba:
      as an aside to Jared's helpful advice, I would point you out to the brand new section on tables included in the Stata.pdf manual, 17th release.
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment


      • #4
        Additionally, if the question is just about calculation
        Code:
        sysuse auto, clear
        mean foreign
        Gives us the percentage of rides that're foreign in this dataset. Note that I'm not at my computer to test the table command, but the way the math works is like any other average. If we have 10 cars and 5 are foreign, we have 5/10 or (1+1+1+1+1)/(10)

        Comment


        • #5
          Hi, I have never used the command but I tried doing it and got the following:
          clear
          input byte(Mental_Health Gender) int Age byte(Marital Educ Employ) float(People_IN_House Inc ethnic)
          1 1 58 1 3 5 1 1.72575 0
          1 2 42 1 3 1 3 .7030833 0
          1 1 23 6 4 7 1 .3068 0
          1 1 21 6 3 1 2 .671125 0
          1 1 30 6 3 3 1 .95875 0
          1 2 18 6 2 1 2 .1534 0
          1 2 24 6 3 2 1 1.72575 0
          1 2 26 4 2 1 2 .287625 0
          1 2 32 1 3 6 3 .57525 0
          1 2 44 1 2 1 2 1.534 0
          1 2 74 1 2 5 1 2.10925 0
          1 1 57 1 3 1 1 1.34225 0
          1 1 68 1 3 5 1 .95875 0
          1 1 71 1 6 5 1 .95875 1
          1 2 23 6 4 1 1 .95875 0
          1 2 44 3 5 2 3 .57525 0
          1 1 21 6 3 1 1 .95875 1
          1 1 32 6 3 1 1 3.068 0
          1 1 45 6 3 1 1 1.72575 0
          1 1 58 4 3 8 2 .671125 0
          1 1 68 1 3 5 1 1.72575 0
          1 1 69 1 3 5 2 .671125 0
          1 2 20 6 3 1 3 .57525 0
          1 2 26 1 3 2 2 .862875 1
          1 2 27 6 5 3 1 1.72575 0
          1 2 30 6 3 1 1 1.34225 0
          1 2 36 5 4 2 2 .287625 0
          1 2 37 1 4 10 2 .862875 0
          1 2 38 1 3 1 2 1.054625 0
          1 2 46 4 2 1 3 .19175 0
          1 2 47 1 3 3 2 1.534 0
          1 2 53 1 1 1 4 .4314375 1
          1 2 68 3 3 5 1 1.34225 0
          1 2 69 3 2 5 1 .57525 0
          1 1 22 6 3 7 4 .767 1
          1 1 23 6 3 1 1 2.10925 0
          1 1 30 6 5 7 1 .57525 0
          1 1 31 1 3 1 3 .57525 0
          1 1 31 6 3 1 1 2.10925 0
          1 1 35 1 2 1 6 .51133335 0
          1 1 38 1 3 1 2 .671125 0
          1 1 40 1 3 1 1 1.72575 0
          1 1 41 3 3 3 1 3.068 0
          1 1 41 6 3 3 1 1.34225 0
          1 1 42 1 3 1 3 .7030833 0
          1 1 47 1 5 2 1 3.068 0
          1 1 47 1 5 3 1 .95875 1
          1 1 50 1 3 3 3 1.5979167 0
          1 1 52 1 3 1 2 1.534 0
          1 1 54 6 3 1 2 1.054625 0
          1 1 55 1 2 1 4 .2396875 0
          1 1 57 1 3 1 1 3.068 0
          1 1 59 1 5 1 2 2.396875 0
          1 1 60 1 5 1 1 2.10925 0
          1 1 61 1 3 5 1 2.10925 0
          1 1 62 1 3 5 2 .862875 0
          1 1 62 1 3 5 1 2.10925 0
          1 1 62 1 5 1 2 .862875 0
          1 1 67 1 2 5 1 1.34225 0
          1 1 68 6 1 5 1 .57525 0
          1 1 69 1 3 5 1 3.068 0
          1 1 70 1 4 5 2 1.054625 0
          1 1 79 1 1 5 1 .57525 0
          1 1 79 3 2 5 2 1.054625 0
          1 2 18 6 2 2 1 .3068 0
          1 2 19 6 4 7 1 .95875 0
          1 2 20 1 3 1 1 2.10925 0
          1 2 20 6 3 1 1 .95875 0
          1 2 20 6 3 1 3 1.0226667 0
          1 2 20 6 3 1 3 1.0226667 0
          1 2 20 6 3 8 3 .7030833 0
          1 2 21 6 3 7 3 1.5979167 0
          1 2 22 6 1 7 2 .671125 1
          1 2 23 6 3 1 5 .6136 0
          1 2 25 6 3 5 1 .95875 0
          1 2 25 6 3 7 2 .1534 0
          1 2 26 6 3 7 1 2.10925 0
          1 2 29 6 3 10 3 .57525 0
          1 2 29 6 5 1 1 .95875 0
          1 2 30 1 3 10 4 .4314375 0
          1 2 30 1 5 10 2 1.054625 1
          1 2 32 1 3 2 3 .7030833 0
          1 2 32 6 3 2 2 1.534 0
          1 2 32 6 4 1 1 .95875 0
          1 2 32 6 3 7 1 .57525 0
          1 2 35 1 3 6 3 .57525 0
          1 2 35 6 3 1 2 1.534 0
          1 2 36 1 3 2 3 .57525 0
          1 2 36 1 3 2 3 1.0226667 0
          1 2 38 1 2 6 3 .3195833 1
          1 2 39 1 3 2 3 .7030833 0
          1 2 39 1 3 6 3 .57525 0
          1 2 41 1 3 1 3 .57525 0
          1 2 42 1 3 6 4 .3355625 0
          1 2 43 1 4 1 3 .57525 0
          1 2 44 1 3 1 6 .51133335 0
          1 2 44 4 4 1 2 .287625 1
          1 2 45 1 5 1 3 1.0226667 0
          1 2 47 1 2 2 1 1.72575 0
          1 2 49 1 3 6 2 1.054625 0
          end
          label values Mental_Health V8
          label def V8 1 "very happy", modify
          label values Gender V302
          label def V302 1 "male", modify
          label def V302 2 "female", modify
          label values Age AGE
          label values Marital V313
          label def V313 1 "married", modify
          label def V313 3 "widowed", modify
          label def V313 4 "divorced", modify
          label def V313 5 "separated", modify
          label def V313 6 "never married or registered partnership", modify
          label values Educ V336
          label def V336 1 " 1 : Primary education or first stage of basic education", modify
          label def V336 2 " 2 : Lower secondary or second stage of basic education", modify
          label def V336 3 " 3 : (Upper) secondary education", modify
          label def V336 4 " 4 : Post-secondary non-tertiary education", modify
          label def V336 5 " 5 : First stage of tertiary education", modify
          label def V336 6 " 6 : Second stage of tertiary education", modify
          label values Employ V337
          label def V337 1 "30h a week or more", modify
          label def V337 2 "less then 30h a week", modify
          label def V337 3 "self employed", modify
          label def V337 5 "retired/pensioned", modify
          label def V337 6 "housewife not otherwise employed", modify
          label def V337 7 "student", modify
          label def V337 8 "unemployed", modify
          label def V337 10 "other", modify
          [/CODE]

          Comment


          • #6
            Any thoughts on how to do it correctly?

            Comment


            • #7
              Taiba:
              looks OK; probably -ethnic- should be -label-led too.
              Kind regards,
              Carlo
              (StataNow 18.5)

              Comment


              • #8
                Okay, so how would I then create the table? I am bit confused

                Comment


                • #9
                  Taiba:
                  see -table- entries in Stata 17 .pdf manual.
                  Kind regards,
                  Carlo
                  (StataNow 18.5)

                  Comment


                  • #10
                    For some reason, it won't allow me to open this. Any other support in trying to create the tables?

                    Comment

                    Working...
                    X