Hi all,

my data look as follows:

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long docdb_family_id strL new_a2 str46 person_ctrycode
 569328 "[1984 1983 1981 1982]"      "['  ']"     
 574660 "[1989 1994 1987 1990 1991]" "['  ']"     
1187498 "[1998 1999 1996]"           "['RU']"     
1226468 "[1996 1992 1994 1993 1997]" "['DE']"     
1236571 "[1991 1993 1990 1996]"      "['US']"     
1239098 "[1995 1992 1993]"           "['US']"     
1239277 "[1996 1993 1992]"           "['IL']"     
1239483 "[1991 1994 1996 1992]"      "['US']"     
1239622 "[1995 1997 1992 1994 1990]" "['FI']"     
1239624 "[1992 1993 1997 1994]"      "['US']"     
1239749 "[1995 1993 1992 1997]"      "['JP']"     
1334477 "[1985]"                     "['  ']"     
1340405 "[1992 1994 1995]"           "['US']"     
1340418 "[1997 1994 1991 1995]"      "['GB']"     
1340462 "[1993 1995 1994]"           "['US']"     
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"
1340485 "[1993 1994 1995]"           "['US']"     
1340488 "[1994 1993 1995 1996]"      "['US' '  ']"
1340508 "[1997 1995 1993 1994]"      "['US']"     
1340519 "[1995 1994 1993 1996]"      "['US']"     
1340541 ""                           "['US']"     
1340647 "[1998 1996 1994 1995]"      "['US' 'CA']"
1340659 "[1995 1997 1996]"           "['CA' '  ']"
1340673 "[1997 1995 1994 1996]"      "['FI' 'US']"
1340826 "[1995 1997]"                "['US']"     
1341006 "[1996 1995 1997]"           "['US']"     
1341170 "[1997 1996 1998]"           "['US']"     
1341175 "[1998 1997]"                "['US']"     
1341188 "[1998 1996 2000]"           "['  ']"     
1578920 "[1972 1971 1970]"           "['DE' 'NL']"
1763337 "[1997 1995 1989]"           "['US' '  ']"
2185207 "[1972]"                     "['  ']"     
2267654 "[1972]"                     "['  ']"     
2410050 "[1972]"                     "['  ']"     
2456718 "[1972]"                     "['  ']"     
2463680 "[1995 1993 1994 1997]"      "['RU']"     
2588926 "[1972]"                     "['  ']"     
2590654 "[1972]"                     "['  ']"     
2856998 "[1972]"                     "['  ']"     
3411930 "[1996 1993 1994]"           "['JP']"     
3459794 "[1972]"                     "['  ']"     
3459918 "[1998]"                     "['JP']"     
3460123 "[1972]"                     "['  ']"     
3460237 "[1995]"                     "['JP']"     
3460351 "[1972]"                     "['  ']"     
3460409 "[1972]"                     "['  ']"     
3460621 "[2008 2004 2005 2003]"      "['ZW']"     
3460636 "[1989]"                     "['GB']"     
3460679 "[1992]"                     "['IT']"     
3460785 "[2001]"                     "['AR']"     
3460796 "[2001 2002 2003]"           "['AR']"     
3460811 "[2001 2002 2004 2003]"      "['AR']"     
3460812 "[2005 2001 2004 2002]"      "['AR']"     
3460829 "[2002 2001 2005]"           "['AR']"     
3460972 "[1998 2000]"                "['AR']"     
3460979 "[2000 1998 1999]"           "['AR']"     
3460980 "[2000]"                     "['AR']"     
3460981 "[2000]"                     "['AR']"     
3461002 "[1998 2000 2002 1999]"      "['  ']"     
3461010 "[1998 1999 2000]"           "['AR' '  ']"
3461018 "[2002 1999 1998]"           "['AR']"     
3461040 "[1999 2001]"                "['US' 'AR']"
3461044 "[1999]"                     "['AR']"     
3461068 "[2000]"                     "['AR']"     
3461084 "[1998 1999 2000]"           "['JP']"     
3461088 "[1999]"                     "['AR']"     
3461099 "[2001]"                     "['AR']"     
3461127 "[2003 2001 2004]"           "['AR']"     
3461128 "[2001 2000 2003 1999]"      "['AR' '  ']"
3461146 "[2001]"                     "['AR']"     
3461172 "[2002 2000]"                "['AR' '  ']"
3461173 "[2002 2001]"                "['AR']"     
3461192 "[2003 2002]"                "['AR']"     
3461205 "[2001 2005]"                "['AR']"     
3461208 "[2001]"                     "['  ' 'AR']"
3461508 "[1970]"                     "['  ']"     
3461552 "[1971]"                     "['  ']"     
3461559 "[1973 1971]"                "['  ']"     
3461677 "[1972]"                     "['  ']"     
3461734 "[1973]"                     "['  ']"     
3462350 "[1974]"                     "['  ']"     
3463151 "[1975]"                     "['  ']"     
3463640 "[1974 1973 1976 1975]"      "['  ']"     
3463716 "[1977 1974 1973]"           "['  ']"     
3464348 "[1975 1977 1976 1974 1978]" "['  ']"     
3464855 "[1975 1976 1978 1974]"      "['AR']"     
3466402 "[1974 1978]"                "['AR']"     
3466535 "[1978 1979 1977]"           "['AR']"     
3467766 "[1979 1978]"                "['  ']"     
3467767 "[1978 1980]"                "['AR']"     
3467833 "[1978 1977 1980 1981]"      "['AR']"     
3467977 "[1977 1978 1976]"           "['AR']"     
3467987 "[1977 1979 1985 1976 1978]" "['  ']"     
3468001 "[1979 1978]"                "['  ']"     
3468888 "[1978 1976]"                "['  ']"     
3469170 "[1976 1977 1978]"           "['  ']"     
3469171 "[1978 1976]"                "['AR']"     
3469272 "[1976 1978]"                "['AR']"     
3470490 "[1981 1979 1977 1982]"      "['AR']"     
3471419 "[1978 1979 1980]"           "['AR']"     
end
I would like however to split first the string person_ctrycode and, whenever more than a country code is present, to put them into two separate lines. For instance,

Code:
input long docdb_family_id strL new_a2 str46 person_ctrycode
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"
should become:

Code:
input long docdb_family_id strL new_a2 str46 person_ctrycode  person_ctrycode2 
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"                       "SE"
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"                       "US"
and so on.

After this, in a separate database, I should repeat the exercise for the variable new_a2. Following the example above, this

Code:
input long docdb_family_id strL new_a2 str46 person_ctrycode
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"
should become:

Code:
input long docdb_family_id strL new_a2 str46 person_ctrycode year2
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"                       1994
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"                       1993
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"                       1995
1340471 "[1994 1993 1995 1996]"      "['SE' 'US']"                       1996
Thank you