Announcement

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

  • Indicator for more than one marital change

    Dear Stata Users,

    I have a panel dataset and I would like to identify marital changes (var marital).
    Suppose that 1 represents single, 2 marriage and 4 divorce, I would like to create a unique indicator that
    considers that the individual 1002352* had a transition from single to marriage AND, then, to divorce.
    So far, I used the lagged operator because I was interested in just one transition and not in the subsequent one.

    But I am not so sure on how to add the second change, Do you have any suggestion?

    ID t marital
    1002352* 1 1
    1002352* 2 2
    1002352* 3 4
    1002352* 5 4
    1002352* 6 4
    1002352* 7 4

    Thank you, Lydia

  • #2
    Code:
    input str10 ID float(t marital)
    "1002352*" 1 1
    "1002352*" 2 2
    "1002352*" 3 4
    "1002352*" 5 4
    "1002352*" 6 4
    "1002352*" 7 4
    end
    
    bys ID (t): gen change= sum(marital!= marital[_n-1]) if _n>1 
    bys ID (t): egen wanted = max(change)
    replace wanted= wanted>1
    Result:

    Code:
     l, sep(6)
    
         +------------------------------------------+
         |       ID   t   marital   change   wanted |
         |------------------------------------------|
      1. | 1002352*   1         1        .        1 |
      2. | 1002352*   2         2        1        1 |
      3. | 1002352*   3         4        2        1 |
      4. | 1002352*   5         4        2        1 |
      5. | 1002352*   6         4        2        1 |
      6. | 1002352*   7         4        2        1 |
         +------------------------------------------+

    Comment

    Working...
    X