Announcement

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

  • Generate the variable for marital history

    Hello! I would be grateful for any help!

    My task is to generate the variable (with such categories: "never married", "in first marriage", "divorced", "widowed", "in second or more marriage") that will reflect the history of marital status. Unfortunately, I have no idea what command can help me.

    I have the dataset:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year float(id marsta)
    1994 1 1
    1995 1 1
    1996 1 1
    1998 1 1
    2000 1 1
    2001 1 1
    2002 1 1
    2003 1 1
    2005 1 1
    2006 1 1
    2007 1 1
    2009 1 3
    2010 1 2
    2011 1 2
    2012 1 3
    2013 1 3
    2014 1 2
    2015 1 2
    2016 1 2
    2017 1 2
    2018 1 2
    2019 1 2
    2020 1 2
    1994 2 1
    1995 2 1
    1996 2 1
    1998 2 1
    2000 2 1
    2001 2 1
    2002 2 1
    2003 2 1
    2004 2 1
    2005 2 1
    2006 2 1
    2007 2 1
    1994 3 2
    1995 3 2
    1996 3 1
    1998 3 3
    2000 3 1
    2001 3 1
    2002 3 1
    2003 3 1
    2008 3 3
    2009 3 3
    2011 3 3
    2012 3 3
    2013 3 3
    2014 3 3
    2015 3 3
    2016 3 3
    2017 3 3
    2018 3 3
    2019 3 3
    2020 3 3
    1994 4 2
    1995 4 2
    1996 4 2
    1998 5 4
    2000 5 4
    2001 5 4
    2002 5 4
    2004 5 4
    2007 5 1
    2008 5 1
    2009 5 1
    2010 5 1
    2011 5 1
    2012 5 1
    2013 5 1
    2014 5 1
    2015 5 1
    2016 5 2
    2017 5 2
    2000 6 4
    2001 6 4
    2002 6 4
    2003 6 4
    2015 6 1
    2016 6 1
    2017 6 1
    2018 6 1
    2019 6 1
    2020 6 1
    1994 7 2
    1995 7 4
    1996 7 4
    1998 7 2
    2000 7 4
    2001 7 4
    2002 7 4
    2003 7 4
    2004 7 2
    2005 7 4
    2006 7 4
    2007 7 4
    2008 7 4
    2009 7 3
    2010 7 3
    2011 7 4
    end
    label values marsta marsta4
    label def marsta4 1 "married", modify
    label def marsta4 2 "divorced", modify
    label def marsta4 3 "widow", modify
    label def marsta4 4 "single", modify

  • #2
    Elvira:
    welcome to this forum.
    Provided that you shared the right data excerpt, there are some inconsitencies to be fixed first:
    Code:
    . bysort id (year): list
    
    <snip>
    -> id = 7
    
         +----------------------+
         | year   id     marsta |
         |----------------------|
      1. | 1994    7   divorced |
      2. | 1995    7     single |
      3. | 1996    7     single |
      4. | 1998    7   divorced |
      5. | 2000    7     single |
         |----------------------|
      6. | 2001    7     single |
      7. | 2002    7     single |
      8. | 2003    7     single |
      9. | 2004    7   divorced |
     10. | 2005    7     single |
         |----------------------|
     11. | 2006    7     single |
     12. | 2007    7     single |
     13. | 2008    7     single |
     14. | 2009    7      widow |
     15. | 2010    7      widow |
         |----------------------|
     16. | 2011    7     single |
         +----------------------+
    
    
    .
    Last edited by Carlo Lazzaro; 25 Aug 2022, 10:18.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X