Announcement

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

  • summarize a variable in panel data

    Hello,

    I want to make a descriptive analysis on variables of my panel data. I have attached the data below.

    What I want to do is see the frequency of fb_age in the dataset. However, as you can see in the data below, the number of observations per h_pid differ and I want stata to count only once for each h_pid.
    For your information, h_pid is the ID number of individuals and fb_age is the age at first childbirth and nchild is the number of children that the individual has.

    When I just do 'sum or tab fb_age, detail', I realised that stata displays the result counting every observations of h_pid.

    Thank you for your help.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long h_pid float(fb_age nchild)
     502 34 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
     602 40 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1001 22 1
    1204 32 1
    1204 32 1
    1204 32 1
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    1502 29 2
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2501 30 1
    2603 27 1
    2603 27 1
    2603 27 1
    2603 27 1
    2702 27 2
    2702 27 2
    3102 28 2
    3102 28 2
    3102 28 2
    3102 28 2
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4202 29 3
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    4502 31 1
    end
    Last edited by Sujin Shin; 09 May 2022, 17:02. Reason: panel data

  • #2
    Try egen tag():

    Code:
    egen unique = tag(h_pid)
    sum fb_age if unique == 1

    Comment

    Working...
    X