-------------------------------------------------------------------------------------------------------------------- name: log: /disk/nber10/SCCS/morg/sources/matchid.log log type: text opened on: 5 Feb 2013, 12:34:23 . set more 1 . program define matchid 1. #delimit cr delimiter now cr . display "Merge previous year for `1'" 2. local lastyear=2011 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 . *matchid 1999 99 98 . *matchid 2000 00 98 . *matchid 2001 01 98 . *matchid 2002 02 98 . matchid 2003 03 03 Merge previous year for 2003 variable match not found r(111); end of do-file r(111); . exit,clear