* Example 4.2.1 * Imort data set to Stata memory import delimited using "data/EXA_C04_S02_01.csv", clear * Take a look at data describe list * Rename the variable to a shorter name rename numberofprograms nprg * Take a look at data, again describe list * Calculate relative percentage and cummulative percentage tabulate nprg [fweight = frequency] * Plot probability density function histogram nprg [fweight = frequency], discrete color(blue) fintensity(inten10) barwidth(0.8) xlabel(#8) * Generate new variables for relative frequency egen totalFreq = sum(frequency) gen Frac = frequency/totalFreq label variable Frac "Relative Frequency" drop totalFreq * Take a look at data, again list * Generate cummulative distribution cumul nprg [fweight = frequency], generate(cum) * Take a look at data, again list * Calculate mean, variance and standard deviation summarize nprg [fweight = frequency], detail * Make the plot of cumulative distribution gen cum1 = cum[_n - 1] replace cum1=0 if cum1==. rename cum cum2 reshape long cum, i(nprg) j(idx) label variable cum "Probability" set obs 17 replace nprg = 0 if nprg==. replace cum = 0 if cum==. set obs 18 replace nprg = 9 if nprg==. replace cum = 1 if cum==. sort nprg idx line cum nprg, sort xlabel(#10)