------------------------------------------------------------------------------------------------------
       log:  c:\Imbook\bwebpage\Section4\mma17p3weib.txt
  log type:  text
 opened on:  19 May 2005, 14:22:25

. 
. ********** OVERVIEW OF MMA17P3WEIB.DO **********
. 
. * STATA Program 
. * copyright C 2005 by A. Colin Cameron and Pravin K. Trivedi 
. * used for "Microeconometrics: Methods and Applications" 
. * by A. Colin Cameron and Pravin K. Trivedi (2005)
. * Cambridge University Press 
. 
. * Chapter 17.6.1 (pages 584-6)
. * Plot of Weibull density, survuvor, hazard and cumulative hazard functions
. * Provides  
. *   (1) Figure 17.2 (ch17weibull.wmf)  
. 
. * This program requires no data
. 
. ********** SETUP **********
. 
. set more off

. version 8.0

. set scheme s1mono   /* Used for graphs */

.   
. ********** GENERATE DATA AND FUNCTIONS **********
. 
. set obs 800
obs was 0, now 800

. 
. gen t = 0.1*_n   /* duration time */

. 
. * Generate the survivor, hazard, cumulative hazard and density
. scalar g = 0.01  /* gamma */

. scalar a = 1.5   /* alpha */

. gen surv = exp(-g*(t^(a)))

. gen density = g*a*(t^(a-1))*exp(-g*(t^(a)))

. gen hazard = g*a*(t^(a-1))

. gen cumhaz = -ln(surv)

. 
. ********** DO THE FOUR SEPARATE GRAPHS FOR FIGURE 17.2 **********
. 
. * Weibull density
. graph twoway (scatter density t, c(l) msize(vtiny) clwidth(medthick) clstyle(p1)), /*
>   */ scale (1.2) plotregion(style(none)) /*
>   */ xtitle("Duration time", size(large)) xscale(titlegap(*5)) /* 
>   */ ytitle("Weibull density", size(large)) yscale(titlegap(*5)) /*
>   */ xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge)) 

. graph save ch17fig2a, replace
(file ch17fig2a.gph saved)

. 
. * Weibull survivor
. graph twoway (scatter surv t, c(l) msize(vtiny) clwidth(medthick) clstyle(p1)), /*
>   */ scale (1.2) plotregion(style(none)) /* 
>   */ xtitle("Duration time", size(large)) xscale(titlegap(*5)) /* 
>   */ ytitle("Weibull survivor", size(large)) yscale(titlegap(*5)) /*
>   */ xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge))

. graph save ch17fig2b, replace
(file ch17fig2b.gph saved)

. 
. * Weibull hazard
. graph twoway (scatter hazard t, c(l) msize(vtiny) clwidth(medthick) clstyle(p1)), /*
>   */ scale (1.2) plotregion(style(none)) /*
>   */ xtitle("Duration time", size(large)) xscale(titlegap(*5)) /* 
>   */ ytitle("Weibull hazard", size(large)) yscale(titlegap(*5)) /*
>   */ xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge))

. graph save ch17fig2c, replace
(file ch17fig2c.gph saved)

. 
. * Weibull cumulative hazard
. graph twoway (scatter cumhaz t, c(l) msize(vtiny) clwidth(medthick) clstyle(p1)), /*
>   */ scale (1.2) plotregion(style(none)) /*
>   */ xtitle("Duration time", size(large)) xscale(titlegap(*5)) /* 
>   */ ytitle("Cumulative hazard", size(large)) yscale(titlegap(*5)) /*
>   */ xlabel(,labsize(medlarge)) ylabel(,labsize(medlarge))

. graph save ch17fig2d, replace
(file ch17fig2d.gph saved)

. 
. ********** COMBINE THE FOUR GRAPHS FOR FIGURE 17.2 (page 585) **********
. 
. graph combine ch17fig2a.gph ch17fig2b.gph ch17fig2c.gph ch17fig2d.gph, /*
>   */ title("Weibull Distribution", margin(b=2) size(vlarge)) 

. graph export ch17weibull.wmf, replace
(file c:\Imbook\bwebpage\Section4\ch17weibull.wmf written in Windows Metafile format)

. 
. ********** CLOSE OUTPUT
. log close
       log:  c:\Imbook\bwebpage\Section4\mma17p3weib.txt
  log type:  text
 closed on:  19 May 2005, 14:22:39
----------------------------------------------------------------------------------------------------
