Announcement

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

  • Generate a table, separated by age and a monetary value

    Greetings,

    I have data on inheritances, and I would like to create a discriptive table to see the % make up of each group for the my data.

    If possible I would like my table to look like this:


    ............inheritance received 0k-10k, 10k-50k, 50k-100k, 100k and above
    age
    16-35
    36-45
    46-55
    56-65
    total


    So basically I want to sort my data by people that have received an inheritance (is a binary variable) and then group them into various age buckets and differntiate between the amounts received, and show the % of each group. How would I do this?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte survey int id byte(implicate gift_received) float gift_total byte age
    1 234 5 1 15000  .
    2 234 1 1  7500 76
    2 234 3 1  7500 76
    2 234 2 1  7500 76
    1 234 2 1 15000  .
    2 234 5 1  7500 76
    2 234 4 1  7500 76
    1 234 1 1 15000  .
    2 234 0 1  7500 76
    1 234 4 1 15000  .
    1 234 3 1 15000  .
    1 234 0 1 15000  .
    2 456 2 2     0  .
    1 456 0 1 50000 54
    2 456 4 2     0  .
    1 456 1 1 50000 54
    2 456 0 2     0  .
    2 456 3 2     0  .
    2 456 5 2     0  .
    1 456 4 1 50000 54
    1 456 3 1 50000 54
    1 456 2 1 50000 54
    1 456 5 1 50000 54
    2 456 1 2     0  .
    end

    survey = time variable, indicates if its from the first or second wave
    id= household id
    implicate = I have multiple imputation (m=5) is this important? As long as the table is in %, this shouldn't affect my table right?
    gift_received = if the person received something (binary)
    gift_total= the amount the person received
    age= age

    How would I go about doing this? Thank you for any help.
    Last edited by Oscar Weinzettl; 28 Apr 2019, 04:17.

  • #2
    Note that your gift intervals are ambiguous (what happens at the boundaries?) and that those under 16 or over 65 are not included in your age classes.

    There isn't really a short-cut here. You just need to define your bins and set up value labels. The code here deliberate mixes various small technique. For more discussions see

    https://journals.sagepub.com/doi/abs...urnalCode=stja

    https://journals.sagepub.com/doi/pdf...867X1201200413 (pdf freely accessible)

    and the help for tabulate or table.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte survey int id byte(implicate gift_received) float gift_total byte age
    1 234 5 1 15000  .
    2 234 1 1  7500 76
    2 234 3 1  7500 76
    2 234 2 1  7500 76
    1 234 2 1 15000  .
    2 234 5 1  7500 76
    2 234 4 1  7500 76
    1 234 1 1 15000  .
    2 234 0 1  7500 76
    1 234 4 1 15000  .
    1 234 3 1 15000  .
    1 234 0 1 15000  .
    2 456 2 2     0  .
    1 456 0 1 50000 54
    2 456 4 2     0  .
    1 456 1 1 50000 54
    2 456 0 2     0  .
    2 456 3 2     0  .
    2 456 5 2     0  .
    1 456 4 1 50000 54
    1 456 3 1 50000 54
    1 456 2 1 50000 54
    1 456 5 1 50000 54
    2 456 1 2     0  .
    end
    
    
    gen age_class = . 
    
    quietly foreach cut in 65 55 45 35 { 
        replace age_class = `cut' if age <= `cut'
    }
    
    label define age_class 35 "16-35"  45 "36-45" 55 "46-55" 65 "56-65" 
    label val age_class age_class 
    
    gen gift_class = 0 if gift_total < . & gift_received == 1 
    
    quietly foreach cut in 1000 10000 50000 100000 { 
        replace gift_class = `cut' if inrange(gift_total, `cut', .)  
    } 
    
    label define gift_class 0 "<1K" 1000 "<10K" 10000 "<100K" 100000 "100K-"
    label val gift_class gift_class 
    
    tab *_class

    Comment


    • #3
      Hi Nick,

      Thank you for your help. Under 16s and over 65 have purposefully been cut from the data. So basically as you said, and showed me in the code (thank you very much for this btw!) I just need to define the bins and what values they include and then use tabulate?

      Comment


      • #4
        Well, you have several people aged 76 in your data example! Otherwise, yes indeed.

        Comment


        • #5
          ye that is just for the dataex, only have a micky mouse data set due to data security. Otherwise I would have already knocked it out.

          Anyway, thanks for your time and help, I really do appreciate it Nick.

          Comment

          Working...
          X