------------------------------------------------------------------------------- log: /disk/u4/SCCS/morg/sources/matchid.log log type: text opened on: 10 Mar 2003, 20:03:40 . set memory 500m (512000k) . set more 1 . program define matchid 1. #delimit cr delimiter now cr . display "Merge previous year for `1'" 2. local lastyear=2002 3. use /homes/data/morg/annual/morg`2' 4. rename match match`2' 5. rename minsamp minsamp`2' 6. egen str2 filmage = concat(mage) 7. replace filmage = "99" if mage==. 8. if `1' == 1979 { 9. gen matchp=0 10. } 11. else if ( `1' <= 2000 & `1' > 1979 ) { 12. local prevyear=`2'-1 13. if ( `1'==2000 ) { 14. local prevyear=99 15. } 16. sort matchid filmage age sex race id 17. display "Merging `1' file using morg`prevyear'.dta (year<=2000)" 18. merge matchid using /homes/data/morg/annual/morg`prevyear'.dta 19. gen matchp =(_merge==3 & minsamp`2'==8) 20. } 21. else if `1' >2000 { 22. local prevyear=`1'-2001 23. sort matchid filmage age sex race id 24. display "Merging `1' file using morg0`prevyear'.dta (year>2000)" 25. merge matchid using /homes/data/morg/annual/morg0`prevyear'.dta 26. gen matchp =( _merge==3 & minsamp`2'==8) 27. } 28. if (`1' > 1979 ) { 29. display "Dropping non-matches from the matchfile" 30. drop if _merge==2 31. display "Dropping the _merge variable" 32. drop _merge 33. } 34. if `1' <1999 { 35. local nextyear = `2' + 1 36. sort matchid age filmage sex race id 37. display "Merging `1' file using morg`nextyear'.dta (year<2000)" 38. merge matchid using /homes/data/morg/annual/morg`nextyear'.dta 39. gen matchn =(_merge==3 & minsamp`2'==4) 40. } 41. else if ( `1' < `lastyear' & `1' >= 1999 ) { 42. local nextyear = `2' + 1 43. if ( `1' ==1999 ) { 44. local nextyear=0 45. } 46. sort matchid age filmage sex race id 47. display "Merging `1' file using morg0`nextyear'.dta (year>=1999 & year > < `lastyear')" 48. merge matchid using /homes/data/morg/annual/morg0`nextyear'.dta 49. gen matchn=( _merge==3 & minsamp`2'==4) 50. } 51. else if ( `1' == `lastyear' ) { 52. gen matchn=0 53. } 54. if ( `1' < `lastyear' ) { 55. display "Dropping non-matches from the matchfile" 56. drop if _merge==2 57. display "Dropping the _merge variable" 58. drop _merge 59. } 60. gen byte match2=matchp+matchn 61. display "Eliminating 'matches' that are too far apart in age" 62. replace match2=0 if nragedif==0 63. replace match`2'=0 if nragedif==0 64. display "Eliminating 'matches' with different sex" 65. list matchid sex if match2==1 & sexdif==0 66. replace match2=0 if sexdif==0 67. replace match`2'=0 if sexdif==0 68. display "Eliminating 'matches' with different race" 69. replace match2=0 if racedif==0 70. replace match`2'=0 if racedif==0 71. *unab vlist: _all . *sort `vlist' . sort mym intmonth state hhid hhnum id lineno 72. quietly by mym intmonth state hhid hhnum id lineno: gen dupm = cond(_N==1, > 0,_n) 73. *quietly by `vlist': gen dupm = cond(_N==1,0,_n) . replace match2=0 if dupm>0 74. replace match`2'=0 if dupm>0 75. sum match`2' match2 76. clear 77. . end . . *matchid 1979 79 79_83 . *matchid 1980 80 79_83 . *matchid 1981 81 79_83 . *matchid 1982 82 79_83 . *matchid 1983 83 79_83 . *matchid 1984 84 84_88 . *matchid 1985 85 84_88 . *matchid 1986 86 84_88 . *matchid 1987 87 84_88 . *matchid 1988 88 84_88 . *matchid 1989 89 89_93 . *matchid 1990 90 89_93 . *matchid 1991 91 89_93 . *matchid 1992 92 89_93 . *matchid 1993 93 89_93 . *matchid 1994 94 94_97 . *matchid 1995 95 94_97 . *matchid 1996 96 94_97 . *matchid 1997 97 94_97 . matchid 1998 98 98 Merge previous year for 1998 (66276 real changes made) Merging 1998 file using morg97.dta (year<=2000) Dropping non-matches from the matchfile (175116 observations deleted) Dropping the _merge variable Merging 1998 file using morg99.dta (year<2000) Dropping non-matches from the matchfile (175967 observations deleted) Dropping the _merge variable Eliminating 'matches' that are too far apart in age (3464 real changes made) (0 real changes made) Eliminating 'matches' with different sex (0 real changes made) (0 real changes made) Eliminating 'matches' with different race (0 real changes made) (0 real changes made) (0 real changes made) (0 real changes made) Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- match98 | 280392 .7447609 .4359963 0 1 match2 | 280392 .7447609 .4359963 0 1 . matchid 1999 99 98 Merge previous year for 1999 (66200 real changes made) Merging 1999 file using morg98.dta (year<=2000) Dropping non-matches from the matchfile (173642 observations deleted) Dropping the _merge variable Merging 1999 file using morg00.dta (year>=1999 & year < 2002) Dropping non-matches from the matchfile (175316 observations deleted) Dropping the _merge variable Eliminating 'matches' that are too far apart in age (3859 real changes made) (0 real changes made) Eliminating 'matches' with different sex (0 real changes made) (0 real changes made) Eliminating 'matches' with different race (0 real changes made) (0 real changes made) (2 real changes made) (2 real changes made) Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- match99 | 282717 .7456644 .4354879 0 1 match2 | 282717 .7456644 .4354879 0 1 . matchid 2000 00 98 Merge previous year for 2000 (67651 real changes made) Merging 2000 file using morg99.dta (year<=2000) Dropping non-matches from the matchfile (174794 observations deleted) Dropping the _merge variable Merging 2000 file using morg01.dta (year>=1999 & year < 2002) Dropping non-matches from the matchfile (197145 observations deleted) Dropping the _merge variable Eliminating 'matches' that are too far apart in age (3826 real changes made) (0 real changes made) Eliminating 'matches' with different sex (0 real changes made) (0 real changes made) Eliminating 'matches' with different race (0 real changes made) (0 real changes made) (5 real changes made) (5 real changes made) Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- match00 | 283239 .7413951 .4378688 0 1 match2 | 283239 .7413951 .4378688 0 1 . *matchid 2001 01 98 . *matchid 2002 02 98 . end of do-file . exit