------------------------------------------------------------------------------------------------------------------------------- name: log: c:\acdbookrevision\stata_final_programs_2013\racd01.txt log type: text opened on: 13 Jan 2013, 15:24:59 . . ********** OVERVIEW OF racd01.do ********** . . * STATA Program . * copyright C 2013 by A. Colin Cameron and Pravin K. Trivedi . * used for "Regression Analyis of Count Data" Second Edition . * by A. Colin Cameron and Pravin K. Trivedi (2013) . * Cambridge University Press . . * Chapter 1 . * 1.3 EXAMPLES . . * To run you need files . * racd01asthma.data . * racd03data.dta health . * racd06data2rectrips.dta . * racd06data4fertilitybritish.dta . . ********** SETUP ********** . . set more off . version 12 . clear all . set linesize 82 . set scheme s1mono /* Graphics scheme */ . . ********** DATA DESCRIPTION ************ . . * The dataset racd01asthma.data is from . * R.A. Davis, W.T.M. Dunsmuir and S.B. Streett (2003), . * "On autocorrelation in a Poisson regression model," Biometrika 87, 491-506. . . * The dataset racd03data.dta is from . * A.C. Cameron and P.K. Trivedi (1986), "Econometric Models Based on . * Count Data: Comparisons and Applications of Some Estimators and Tests", . * Journal of Applied Econometrics, Vol. 1, pp. 29-54. . . * The data in racd06data2rectrips.dta are from . * C. Sellar, J.R. Stoll and J.P. Chavas (1985), "Validation of Empirical . * Measures of Welfare Change: A Comparison of nonmarket Techniques," . * Land Economics, 61, 156-175. . * Data used with permission of Sellar et al. (1985) . . * The data in racd06data4fertilitybritish.dta are authors own data. . . ********** 1.3 EXAMPLES: Create Figures 1.1 and 1.2 . . use racd03data.dta, clear . sum DVISITS Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- DVISITS | 5190 .3017341 .7981338 0 9 . di "Mean: " r(mean) " Variance: " r(Var) Mean: .3017341 Variance: .63701761 . label variable DVISITS "Number of doctor visits" . histogram DVISITS, discrete frequency barwidth(0.8) saving(racd01graph1, replace > ) xlabel(#6) (start=0, width=1) (file racd01graph1.gph saved) . . clear . set obs 5190 obs was 0, now 5190 . generate xpoisson = rpoisson(0.3) . sum xpoisson Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- xpoisson | 5190 .3046243 .5481954 0 4 . di "Mean: " r(mean) " Variance: " r(Var) Mean: .30462428 Variance: .30051821 . label variable xpoisson "Generated Poisson with mean 0.3" . histogram xpoisson, discrete frequency barwidth(0.8) saving(racd01graph2, replac > e) xlabel(#6) (start=0, width=1) (file racd01graph2.gph saved) . . use racd06data2rectrips.dta, clear . sum TRIPS Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- TRIPS | 659 2.24431 6.292475 0 88 . di "Mean: " r(mean) " Variance: " r(Var) Mean: 2.2443096 Variance: 39.595237 . label variable TRIPS "Number of recreational trips" . histogram TRIPS if TRIPS < 15, discrete frequency barwidth(0.8) saving(racd01gra > ph3, replace) xlabel(#6) (start=0, width=1) (file racd01graph3.gph saved) . . use racd06data4fertilitybritish.dta, clear (Completed fertility Data --- BHPS, updated up to to wave W18) . sum children Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- children | 6782 1.856532 1.508928 0 11 . di "Mean: " r(mean) " Variance: " r(Var) Mean: 1.856532 Variance: 2.2768627 . label variable children "Number of children" . histogram children, discrete frequency barwidth(0.8) saving(racd01graph4, replac > e) xlabel(#6) (start=0, width=1) (file racd01graph4.gph saved) . . *** FIGURE 1.1: FOUR HISTOGRAMS . . graph combine racd01graph1.gph racd01graph2.gph racd01graph3.gph racd01graph4.gp > h, /// > iscale(0.7) ysize(5) xsize(6) xcommon rows(2) . . graph export racd01fig1.eps, replace (file racd01fig1.eps written in EPS format) . graph export racd01fig1.wmf, replace (file c:\acdbookrevision\stata_final_programs_2013\racd01fig1.wmf written in Windo > ws Metafile format) . . use racd01asthmadata.dta, clear . sum Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- campbelltown | 1461 1.939083 1.643913 0 14 month | 1461 6.52293 3.449884 1 12 x_sunday | 1461 .1423682 .3495471 0 1 x_monday | 1461 .1430527 .3502465 0 1 c1 | 1461 .0006844 .7075905 -.999963 1 -------------+-------------------------------------------------------- s1 | 1461 .0000118 .7071069 -.9999908 .9999908 t1_1990 | 1461 .0683106 .3411904 0 2.38123 t2_1990 | 1461 .0683106 .3411904 0 2.38123 t1_1991 | 1461 .0683106 .3411904 0 2.38123 t2_1991 | 1461 .0683106 .3411904 0 2.38123 -------------+-------------------------------------------------------- t1_1992 | 1461 .0683106 .3411904 0 2.38123 t2_1992 | 1461 .0683106 .3411904 0 2.38123 t1_1993 | 1461 .0683106 .3411904 0 2.38123 t2_1993 | 1461 .0683106 .3411904 0 2.38123 h7 | 1461 .1441841 7.512605 -22.36524 23.28903 -------------+-------------------------------------------------------- no2max | 1461 1.595396 .7627092 .0298611 5.008102 ozonemax | 1461 .8904032 .4421329 0 4.416087 nephmax | 1461 .3080964 .2373286 .0039583 1.670833 no2maxlag1 | 1461 1.594958 .7631542 .0298611 5.008102 ozonemaxlag1 | 1461 .8900194 .4417938 0 4.416087 -------------+-------------------------------------------------------- nephmaxlag1 | 1461 .3080778 .237336 .0039583 1.670833 time | 1461 731 421.8987 1 1461 y | 1461 1.939083 1.643913 0 14 ysq | 1461 6.460643 11.59727 0 196 . sum campbelltown Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- campbelltown | 1461 1.939083 1.643913 0 14 . di "Mean: " r(mean) " Variance: " r(Var) Mean: 1.9390828 Variance: 2.7024509 . label variable campbelltown "Admissions for asthma" . label variable time "Day" . . histogram campbelltown, discrete frequency barwidth(0.8) saving(racd01graph5, re > place) xlabel(#6) (start=0, width=1) (file racd01graph5.gph saved) . . tsline campbelltown if time < 100, saving(racd01graph6, replace) xlabel(#6) (file racd01graph6.gph saved) . . ac campbelltown, saving(racd01graph7, replace) lags(20) note(" ") xlabel(#6) /// > ciopts(fintensity(inten10)) ytitle("Autocorrelations of asthma admissions") (file racd01graph7.gph saved) . . generate sqcampbelltown = campbelltown^2 . ac sqcampbelltown, saving(racd01graph8, replace) lags(20) note(" ") xlabel(#6) / > // > ciopts(fintensity(inten10)) ytitle("Autocorrelations of squared asthma") (file racd01graph8.gph saved) . . ** FIGURE 1.2: ASTHMA DATA . . graph combine racd01graph5.gph racd01graph6.gph racd01graph7.gph racd01graph8.gp > h, /// > iscale(0.7) ysize(5) xsize(6) rows(2) . . graph export racd01fig2.eps, replace (file racd01fig2.eps written in EPS format) . graph export racd01fig2.wmf, replace (file c:\acdbookrevision\stata_final_programs_2013\racd01fig2.wmf written in Windo > ws Metafile format) . . ********** CLOSE OUTPUT . . * log close . * clear . * exit . . end of do-file . exit, clear