Announcement

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

  • Duplicate indicators- Expand function

    Hello,

    Using the function "Expand 3" or "Expand 5", I would like to be able to distinguish the new observations created so that I can modify them independently of each other.

    For example, I use the following line of code:

    "expand 3 if num_quest==787 & year_start==1991, gen(dupindicator)"
    *dupindicator= duplicate indicator


    This creates one observation with dupindicator=0 and 2 observations with dupindicator=1.

    How to create dupindicators with different values (ex. 0, 1, 2)?

  • #2
    The expand command (not function) clones observations. Anything else to differentiate that must follow.

    Code:
    clear 
    set obs 2 
    
    gen x = _n 
    
    expand 3 if x == 2, gen(triple)
    
    bysort x (triple): gen new = _n - 1 if x == 2 
    
    list, sepby(x)
    
         +--------------------+
         | x     triple   new |
         |--------------------|
      1. | 1   Original     . |
         |--------------------|
      2. | 2   Original     0 |
      3. | 2   Duplicat     1 |
      4. | 2   Duplicat     2 |
         +--------------------+

    Comment


    • #3
      Thank you!!

      Comment

      Working...
      X