fsu seal Florida State University
  Center home >> Minxing >> sya6933>> assignment2
 

***Homework Assignment 2 Solution***


/************* HW 2 Solution *************/ /***2.1**/ infile id str10 bday str5 admday using x:\sya6933\week4\date1.txt,clear gen bdate=date(bday,"md19y") gen adate=dofm(monthly(admday,"m19y"))+14 list +-------------------------------------------+ | id bday admday bdate adate | |-------------------------------------------| 1. | 22102 01/21/52 7/85 -2902 9327 | 2. | 28559 07/11/48 11/92 -4191 12007 | 3. | 11451 10/28/62 5/90 1031 11092 | +-------------------------------------------+ gen age=(adate-bdate)/365.25 format bdate %d format adate %d list +--------------------------------------------------------------+ | id bday admday bdate adate age | |--------------------------------------------------------------| 1. | 22102 01/21/52 7/85 21jan1952 15jul1985 33.48118 | 2. | 28559 07/11/48 11/92 11jul1948 15nov1992 44.34771 | 3. | 11451 10/28/62 5/90 28oct1962 15may1990 27.54552 | +--------------------------------------------------------------+ /*****2.2*******/ . use x:\sya6933\hw2\nlsy.dta,clear (National Longitudinal Survey of Youth, 1979, Dataset 0001) . gen bday1=string(bday) . gen month=substr(bday1,5,2) (3 missing values generated) . gen year=substr(bday1,1,4) . destring month year,replace month has all characters numeric; replaced as byte (3 missing values generated) year has all characters numeric; replaced as int . gen day=month+10 (3 missing values generated) . gen birthday=mdy(month,day,year) (3 missing values generated) . format birthday %d . list in 1/30 +----------------------------------------------------------------------+ | id race sex bday bday1 month year day birthday | |----------------------------------------------------------------------| 1. | 201 3 2 199303 199303 3 1993 13 13mar1993 | 2. | 202 3 2 199411 199411 11 1994 21 21nov1994 | 3. | 301 3 2 198106 198106 6 1981 16 16jun1981 | 4. | 302 3 2 198310 198310 10 1983 20 20oct1983 | 5. | 303 3 2 198604 198604 4 1986 14 14apr1986 | |----------------------------------------------------------------------| 6. | 401 3 1 198008 198008 8 1980 18 18aug1980 | 7. | 403 3 2 199703 199703 3 1997 13 13mar1997 | 8. | 801 3 2 197603 197603 3 1976 13 13mar1976 | 9. | 802 3 1 197905 197905 5 1979 15 15may1979 | 10. | 803 3 2 198209 198209 9 1982 19 19sep1982 | |----------------------------------------------------------------------| 11. | 1001 3 2 198301 198301 1 1983 11 11jan1983 | 12. | 1002 3 2 198807 198807 7 1988 17 17jul1988 | 13. | 1201 3 1 198910 198910 10 1989 20 20oct1989 | 14. | 1202 3 1 199308 199308 8 1993 18 18aug1993 | 15. | 1601 3 1 199002 199002 2 1990 12 12feb1990 | |----------------------------------------------------------------------| 16. | 1602 3 1 199308 199308 8 1993 18 18aug1993 | 17. | 1603 3 2 199609 199609 9 1996 19 19sep1996 | 18. | 1901 3 2 198711 198711 11 1987 21 21nov1987 | 19. | 2001 3 2 199008 199008 8 1990 18 18aug1990 | 20. | 2501 3 1 199010 199010 10 1990 20 20oct1990 | |----------------------------------------------------------------------| 21. | 2502 3 2 199308 199308 8 1993 18 18aug1993 | 22. | 2701 3 2 198802 198802 2 1988 12 12feb1988 | 23. | 2702 3 1 199201 199201 1 1992 11 11jan1992 | 24. | 3001 3 1 198212 198212 12 1982 22 22dec1982 | 25. | 3002 3 1 198703 198703 3 1987 13 13mar1987 | |----------------------------------------------------------------------| 26. | 3003 3 1 199110 199110 10 1991 20 20oct1991 | 27. | 3501 3 2 199005 199005 5 1990 15 15may1990 | 28. | 3502 3 2 199306 199306 6 1993 16 16jun1993 | 29. | 3701 3 2 199004 199004 4 1990 14 14apr1990 | 30. | 4301 3 2 198210 198210 10 1982 20 20oct1982 | +----------------------------------------------------------------------+ . display d(1jan1983) 8401 . display d(31may1983) 8551 . count if birthday>=8401&birthday<=8551 281 . end of do-file