Announcement

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

  • generating group

    family_number solo_parent relation_family assessment_age
    123456n-1 0 1 40
    123456n-1 1 2 25
    123456n-1 0 3 2
    123456n-2 0 1 40
    123456n-2 0 2 35
    123456n-2 0 3 10
    123400n-1 1 1 20
    123400n-1 0 3 2
    123400n-1 0 3 1
    123400n-2 1 1 30
    123400n-2 0 3 10
    Hi,

    what will be the codes to generate the number of solo_parent with child/children aged 3 years old and below (relation_family==3)?

    thank you.

  • #2
    Welcome to Statalist.

    I'm not certain I understand what you are looking for, but perhaps this code will help you.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str9 family_number byte(solo_parent relation_family assessment_age)
    "123456n-1" 0 1 40
    "123456n-1" 1 2 25
    "123456n-1" 0 3  2
    "123456n-2" 0 1 40
    "123456n-2" 0 2 35
    "123456n-2" 0 3 10
    "123400n-1" 1 1 20
    "123400n-1" 0 3  2
    "123400n-1" 0 3  1
    "123400n-2" 1 1 30
    "123400n-2" 0 3 10
    end
    generate child = relation_family==3 & assessment_age<=3
    assert ! missing(child)
    bysort family_number (relation_family): egen has_ch = max(child)
    tab has_ch if solo_parent
    list, sepby(family_number)
    Code:
    . tab has_ch if solo_parent
    
         has_ch |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |          1       33.33       33.33
              1 |          2       66.67      100.00
    ------------+-----------------------------------
          Total |          3      100.00
    
    . list, sepby(family_number)
    
         +-------------------------------------------------------------+
         | family_~r   solo_p~t   relati~y   assess~e   child   has_ch |
         |-------------------------------------------------------------|
      1. | 123400n-1          1          1         20       0        1 |
      2. | 123400n-1          0          3          2       1        1 |
      3. | 123400n-1          0          3          1       1        1 |
         |-------------------------------------------------------------|
      4. | 123400n-2          1          1         30       0        0 |
      5. | 123400n-2          0          3         10       0        0 |
         |-------------------------------------------------------------|
      6. | 123456n-1          0          1         40       0        1 |
      7. | 123456n-1          1          2         25       0        1 |
      8. | 123456n-1          0          3          2       1        1 |
         |-------------------------------------------------------------|
      9. | 123456n-2          0          1         40       0        0 |
     10. | 123456n-2          0          2         35       0        0 |
     11. | 123456n-2          0          3         10       0        0 |
         +-------------------------------------------------------------+
    With that said, some advice to improve your future posts.

    Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using CODE delimiters, and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

    Comment

    Working...
    X