Announcement

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

  • EXPAND observations and assign values to the dupliates

    Dear Statalist Forum,

    I want to expand observations by using the expand command; I want to make 5 duplicates, so that I have 6 observations instead of one:

    expand 5, gen(newobs)

    So far, so clear. Now I want to generate a new variable that assigns a value between 60 and 65 to each of the duplicates.
    Example:

    Sex birthyear newobs newvar
    male 1937 0 60
    male 1937 1 61
    male 1937 1 62
    male 1937 1 63
    male 1937 1 64
    male 1937 1 65


    I have no idea how to do this. Any help is greatly appreciated.


    Cheers,
    Barbara

  • #2
    Code:
    expand 5, gen(newobs)
    egen newvar= fill (60 61 62 63 64 65 60 61 62 63 64 65)

    Comment


    • #3
      Dear Pierre,
      thanks for your reply, but that doesn't really work out.
      First of all, it has to be "expand 6" (my fault); second, with your egen command, I never get the values 60-65 for one id, but rather 60 60 61 62 64 for the first id, 60 61 61 62 63 65 for the second ID etc.

      Comment


      • #4
        How about

        Code:
        clear
        input Sex birthyear
        1 1937
        2 1940
        end
        list
        gen ncase = _n
        expand 6, gen(newobs)
        bysort ncase (newobs): gen newvar = _n + 59
        list, sepby(ncase)
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 17.0 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment

        Working...
        X