| [48] | mcas.dta | |||
| [456] | production.dta | |||
|
ch2.0.do:28 ch2.0.do:29 |
[487] | [+] lcensus2 | ||
| [494] | mcsimul.dta | |||
| master.do:8 | ||||
| → | ch11.01.do | ↘ | ||
|
MCAS |
[256] | |||
ch11.01.do open
file:script:do
| # | content |
|---|---|
| 1 [+] | * itsp 11.01 - |
| 3 [+] | capture program drop parrot |
| 5 [+] | type parrot.ado |
| 6 [+] | parrot "This is Stata..." |
| 9 [+] | /* program define double2, rclass version 10.1 * local doubled = `0'+`0' display "`0' doubled is `=`0'+`0''" " end */ |
| 17 [+] | !rm pctrange.ado |
| 18 [+] | !cp pctrange.100.ado pctrange.ado |
| 19 [+] | program drop _all |
| 20 [+] | which pctrange |
| 22 [+] | type pctrange.ado |
| 24 [+] | /* *! pctrange v1.0.0 CFBaum 22jul2007 program pctrange, rclass version 10.1 syntax varlist(max=1 numeric) quietly summarize `varlist', detail scalar range = r(max) - r(min) scalar p7525 = r(p75) - r(p25) scalar p9010 = r(p90) - r(p10) scalar p9505 = r(p95) - r(p5) scalar p9901 = r(p99) - r(p1) display as result _n "Percentile ranges for `varlist'" display as txt "75-25: " p7525 display as txt "90-10: " p9010 display as txt "95-05: " p9505 display as txt "99-01: " p9901 display as txt "Range: " range end */ |
| 45 [+] | * use http://fmwww.bc.edu/ec-p/data/stockwatson/mcas, clear |
| 47 [+] | clear |
| 48 [+] | use mcas |
| 49 [+] | pctrange tot_day |
| 50 [+] | display p7525 |
| 52 [+] | !cp pctrange.101.ado pctrange.ado |
| 53 [+] | program drop _all |
| 54 [+] | which pctrange |
| 56 [+] | type pctrange.ado |
| 58 [+] | /* capture program drop pctrange *! pctrange v1.0.1 CFBaum 22jul2007 program pctrange, rclass version 10.1 syntax varlist(max=1 numeric) local res range p7525 p9010 p9505 p9901 tempname `res' display as result _n "Percentile ranges for `varlist'" quietly summarize `varlist', detail scalar `range' = r(max) - r(min) scalar `p7525' = r(p75) - r(p25) scalar `p9010' = r(p90) - r(p10) scalar `p9505' = r(p95) - r(p5) scalar `p9901' = r(p99) - r(p1) display as txt "75-25: " `p7525' display as txt "90-10: " `p9010' display as txt "95-05: " `p9505' display as txt "99-01: " `p9901' display as txt "Range: " `range' foreach r of local res { return scalar `r' = ``r'' } end */ |
| 85 [+] | !cp pctrange.102.ado pctrange.ado |
| 86 [+] | program drop _all |
| 87 [+] | which pctrange |
| 89 [+] | type pctrange.ado |
| 91 [+] | quietly pctrange tot_day |
| 92 [+] | return list |
| 94 [+] | !cp pctrange.103.ado pctrange.ado |
| 95 [+] | program drop _all |
| 96 [+] | which pctrange |
| 98 [+] | type pctrange.ado |
| 100 [+] | !cp pctrange.104.ado pctrange.ado |
| 101 [+] | program drop _all |
| 102 [+] | which pctrange |
| 104 [+] | type pctrange.ado |
| 106 [+] | !cp pctrange.105.ado pctrange.ado |
| 107 [+] | program drop _all |
| 108 [+] | which pctrange |
| 110 [+] | type pctrange.ado |
| 113 [+] | /* capture program drop pctrange *! pctrange v1.0.3 CFBaum 22jul2007 program pctrange, rclass version 10.1 syntax varlist(max=1 numeric) [, noPRINT] local res range p7525 p9010 p9505 p9901 tempname `res' quietly summarize `varlist', detail scalar `range' = r(max) - r(min) scalar `p7525' = r(p75) - r(p25) scalar `p9010' = r(p90) - r(p10) scalar `p9505' = r(p95) - r(p5) scalar `p9901' = r(p99) - r(p1) if "`print'" != "noprint" { display as result _n "Percentile ranges for `varlist'" display as txt "75-25: " `p7525' display as txt "90-10: " `p9010' display as txt "95-05: " `p9505' display as txt "99-01: " `p9901' display as txt "Range: " `range' } foreach r of local res { return scalar `r' = ``r'' } end capture program drop pctrange *! pctrange v1.0.3 CFBaum 22jul2007 program pctrange, rclass version 10.1 syntax varlist(max=1 numeric) [if] [in] [, noPRINT] marksample touse quietly count if `touse' if `r(N)' == 0 { error 2000 } local res range p7525 p9010 p9505 p9901 tempname `res' quietly summarize `varlist' if `touse', detail scalar `range' = r(max) - r(min) scalar `p7525' = r(p75) - r(p25) scalar `p9010' = r(p90) - r(p10) scalar `p9505' = r(p95) - r(p5) scalar `p9901' = r(p99) - r(p1) if "`print'" != "noprint" { display as result _n "Percentile ranges for `varlist', N = `r(N)'" display as txt "75-25: " `p7525' display as txt "90-10: " `p9010' display as txt "95-05: " `p9505' display as txt "99-01: " `p9901' display as txt "Range: " `range' } foreach r of local res { return scalar `r' = ``r'' } return scalar N = r(N) return local var `varlist' end */ |
| 177 [+] | summarize percap , |
| 178 [+] | pctrange tot_day if percap > r(mean) & !missing(percap) |
| 180 [+] | !cp pctrange.106.ado pctrange.ado |
| 181 [+] | program drop _all |
| 182 [+] | which pctrange |
| 184 [+] | type pctrange.ado |
| 186 [+] | /* capture program drop pctrange *! pctrange v1.0.4 CFBaum 22jul2007 program pctrange, rclass version 10.1 syntax varlist(min=1 numeric) [if] [in] [, noPRINT FORmat(passthru) MATrix(string)] marksample touse quietly count if `touse' if `r(N)' == 0 { error 2000 } local nvar : word count `varlist' if `nvar' == 1 { local res range p7525 p9010 p9505 p9901 tempname `res' quietly summarize `varlist' if `touse', detail scalar `p7525' = r(p75) - r(p25) scalar `p9010' = r(p90) - r(p10) scalar `p9505' = r(p95) - r(p5) scalar `p9901' = r(p99) - r(p1) scalar `range' = r(max) - r(min) if "`print'" != "noprint" { display as result _n "Percentile ranges for `varlist', N = `r(N)'" display as txt "75-25: " `p7525' display as txt "90-10: " `p9010' display as txt "95-05: " `p9505' display as txt "99-01: " `p9901' display as txt "Range: " `range' } foreach r of local res { return scalar `r' = ``r'' } return scalar N = r(N) } else { tempname rmat matrix `rmat' = J(`nvar',5,.) local i 0 foreach v of varlist `varlist' { local ++i quietly summarize `v' if `touse', detail matrix `rmat'[`i', 1] = r(p75) - r(p25) matrix `rmat'[`i', 2] = r(p90) - r(p10) matrix `rmat'[`i', 3] = r(p95) - r(p5) matrix `rmat'[`i', 4] = r(p99) - r(p1) matrix `rmat'[`i', 5] = r(max) - r(min) local rown "`rown' `v'" } matrix colnames `rmat' = P75-P25 P90-P10 P95-P05 P99-P01 Range matrix rownames `rmat' = `rown' if "`print'" != "noprint" { local form ", noheader" if "`format'" != "" { local form "`form' `format'" } matrix list `rmat' `form' } if "`matrix'" != "" { matrix `matrix' = `rmat' } return matrix rmat = `rmat' } return local varname `varlist' end */ |
| 253 [+] | pctrange regday specneed bilingua occupday tot_day tchratio , |
| 255 [+] | pctrange regday specneed bilingua occupday tot_day tchratio , |
| 256 [+] | outtable using MCAS , |
| 258 [+] | /* capture program drop pctrange *! pctrange v1.0.6 CFBaum 22jul2007 program pctrange, rclass byable(recall) version 10.1 syntax varlist(min=1 numeric ts) [if] [in] [, noPRINT FORmat(passthru) MATrix(string)] marksample touse quietly count if `touse' if `r(N)' == 0 { error 2000 } local nvar : word count `varlist' if `nvar' == 1 { local res range p7525 p9010 p9505 p9901 tempname `res' quietly summarize `varlist' if `touse', detail scalar `range' = r(max) - r(min) scalar `p7525' = r(p75) - r(p25) scalar `p9010' = r(p90) - r(p10) scalar `p9505' = r(p95) - r(p5) scalar `p9901' = r(p99) - r(p1) if "`print'" != "noprint" { display as result _n "Percentile ranges for `varlist', N = `r(N)'" display as txt "75-25: " `p7525' display as txt "90-10: " `p9010' display as txt "95-05: " `p9505' display as txt "99-01: " `p9901' display as txt "Range: " `range' } foreach r of local res { return scalar `r' = ``r'' } return scalar N = r(N) } else { tempname rmat matrix `rmat' = J(`nvar',5,.) local i 0 foreach v of varlist `varlist' { local ++i quietly summarize `v' if `touse', detail matrix `rmat'[`i',1] = r(max) - r(min) matrix `rmat'[`i',2] = r(p75) - r(p25) matrix `rmat'[`i',3] = r(p90) - r(p10) matrix `rmat'[`i',4] = r(p95) - r(p5) matrix `rmat'[`i',5] = r(p99) - r(p1) local rown "`rown' `v'" } matrix colnames `rmat' = Range P75-P25 P90-P10 P95-P05 P99-P01 matrix rownames `rmat' = `rown' if "`print'" != "noprint" { local form ", noheader" if "`format'" != "" { local form "`form' `format'" } matrix list `rmat' `form' } if "`matrix'" != "" { matrix `matrix' = `rmat' } return matrix rmat = `rmat' } return local var `varlist' end */ |
| 325 [+] | summarize avgsalry , |
| 326 [+] | generate byte highsal = avgsalry > r(mean) & !missing(avgsalry) |
| 327 [+] | label define sal 0 low 1 high |
| 328 [+] | label val highsal sal |
| 329 [+] | tabstat avgsalry , |
| 330 [+] | bysort highsal: pctrange regday specneed bilingua occupday tot_day tchratio |
| 333 [+] | !cp _gpct9010.100.ado _gpct9010.ado |
| 334 [+] | program drop _all |
| 335 [+] | which _gpct9010 |
| 337 [+] | type _gpct9010.ado |
| 339 [+] | /* capture program drop _gpct9010 *! _gpct9010 v1.0.0 CFBaum 30jul2007 program _gpct9010 version 10.1 syntax newvarname =/exp [if] [in] tempvar touse mark `touse' `if' `in' quietly summarize `exp' if `touse', detail quietly generate `typlist' `varlist' = r(p90) - r(p10) if `touse' end capture program drop _gpct9010 *! _gpct9010 v1.0.1 CFBaum 30jul2007 program _gpct9010 version 10.1 syntax newvarname =/exp [if] [in] [, *] tempvar touse p90 p10 mark `touse' `if' `in' quietly { egen double `p90' = pctile(`exp') if `touse', `options' p(90) egen double `p10' = pctile(`exp') if `touse', `options' p(10) generate `typlist' `varlist' = `p90' - `p10' if `touse' } end */ |
| 367 [+] | !cp _gpct9010.101.ado _gpct9010.ado |
| 368 [+] | program drop _all |
| 369 [+] | which _gpct9010 |
| 371 [+] | type _gpct9010.ado |
| 373 [+] | sysuse auto , |
| 374 [+] | bysort rep78 foreign: egen pctrange = pct9010(price) |
| 376 [+] | chelp pctrange |
| 378 [+] | !cp mynormal_lf.100.ado mynormal_lf.ado |
| 379 [+] | program drop _all |
| 380 [+] | which mynormal_lf |
| 382 [+] | type mynormal_lf.ado |
| 383 [+] | /* capt program drop mynormal_lf program mynormal_lf version 10.1 args lnf mu sigma quietly replace `lnf' = ln(normalden($ML_y1, `mu', `sigma')) end */ |
| 392 [+] | !cp mynormal.100.ado mynormal.ado |
| 393 [+] | program drop _all |
| 394 [+] | which mynormal |
| 396 [+] | type mynormal.ado |
| 398 [+] | /* capture program drop mynormal Replay Estimate program mynormal version 10.1 if replay() { if ("`e(cmd)'" != "mynormal") error 301 Replay `0' } else Estimate `0' end program Replay syntax [, Level(cilevel) ] ml display, level(`level') end program Estimate, eclass sortpreserve syntax varlist [if] [in] [, vce(passthru) Level(cilevel) * ] mlopts mlopts, `options' gettoken lhs rhs: varlist marksample touse ml model lf mynormal_lf (mu: `lhs' = `rhs') /sigma /// if `touse', `vce' `mlopts' maximize ereturn local cmd "mynormal" Replay, level(`level') end */ |
| 426 [+] | sysuse auto , |
| 427 [+] | mynormal price mpg weight turn |
| 429 [+] | mynormal , |
| 430 [+] | test weight = 5 |
| 431 [+] | predict double pricehat , |
| 432 [+] | summarize price pricehat |
| 435 [+] | type nlces.ado |
| 436 [+] | /* capture program drop nlces program nlces version 10.1 syntax varlist(min=3 max=3) if, at(name) tokenize `varlist' args logoutput K L tempname b0 rho delta tempvar kterm lterm scalar `b0' = `at'[1, 1] scalar `rho' = `at'[1, 2] scalar `delta' = `at'[1, 3] gen double `kterm' = `delta' * `K'^(-(`rho')) `if' gen double `lterm' = (1 - `delta') *`L'^(-(`rho')) `if' replace `logoutput' = `b0' - 1 / `rho' * ln(`kterm' + `lterm') `if' end */ |
| 454 [+] | * webuse production, clear |
| 456 [+] | use production , |
| 457 [+] | nl ces @ lnoutput capital labor , /// initial(b0 0 rho 1 delta 0.5) |
| 460 [+] | nlcom (sigma: 1 / (1 + [rho]_b[_cons])) |
| 462 [+] | // generate `y1' = medage + invnorm(uniform()) * 0.05 * zmu // generate `y2' = medage + invnorm(uniform()) * 0.05 * z_factor |
| 465 [+] | program drop _all |
| 466 [+] | which mcsimul |
| 468 [+] | type mcsimul.ado |
| 470 [+] | /* capt program drop mcsimul program mcsimul, rclass version 10.1 tempvar y1 y2 generate `y1' = drate + invnorm(uniform()) * 0.05 * zmu generate `y2' = drate + invnorm(uniform()) * 0.05 * z_factor ttest `y1' = 80 return scalar p1 = r(p) ttest `y2' = 80 return scalar p2 = r(p) end */ |
| 484 [+] | * webuse census2, clear |
| 486 [+] | set seed 20070731 |
| 487 [+] | use census2 , |
| 488 [+] | generate z_factor = 10 * region |
| 489 [+] | summarize z_factor , |
| 490 [+] | scalar zmu = r(mean) |
| 491 [+] | quietly simulate p1=r(p1) p2=r(p2) , /// saving(mcsimul,replace) nodots reps(1000): mcsimul drate, mu(80) |
| 494 [+] | use mcsimul , |
| 495 [+] | generate R5pc_1 = (p1 < 0.05) |
| 496 [+] | generate R5pc_2 = (p2 < 0.05) |
| 497 [+] | summarize |
* itsp 11.01 -
capture program drop parrot
type parrot.ado
parrot "This is Stata..."
* doubled is " `1'+`1'
/*
program define double2, rclass
version 10.1
* local doubled = `0'+`0'
display "`0' doubled is `=`0'+`0''" "
end
*/
!rm pctrange.ado
!cp pctrange.100.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
/*
*! pctrange v1.0.0 CFBaum 22jul2007
program pctrange, rclass
version 10.1
syntax varlist(max=1 numeric)
quietly summarize `varlist', detail
scalar range = r(max) - r(min)
scalar p7525 = r(p75) - r(p25)
scalar p9010 = r(p90) - r(p10)
scalar p9505 = r(p95) - r(p5)
scalar p9901 = r(p99) - r(p1)
display as result _n "Percentile ranges for `varlist'"
display as txt "75-25: " p7525
display as txt "90-10: " p9010
display as txt "95-05: " p9505
display as txt "99-01: " p9901
display as txt "Range: " range
end
*/
* use http://fmwww.bc.edu/ec-p/data/stockwatson/mcas, clear
clear
use mcas
pctrange tot_day
display p7525
!cp pctrange.101.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
/*
capture program drop pctrange
*! pctrange v1.0.1 CFBaum 22jul2007
program pctrange, rclass
version 10.1
syntax varlist(max=1 numeric)
local res range p7525 p9010 p9505 p9901
tempname `res'
display as result _n "Percentile ranges for `varlist'"
quietly summarize `varlist', detail
scalar `range' = r(max) - r(min)
scalar `p7525' = r(p75) - r(p25)
scalar `p9010' = r(p90) - r(p10)
scalar `p9505' = r(p95) - r(p5)
scalar `p9901' = r(p99) - r(p1)
display as txt "75-25: " `p7525'
display as txt "90-10: " `p9010'
display as txt "95-05: " `p9505'
display as txt "99-01: " `p9901'
display as txt "Range: " `range'
foreach r of local res {
return scalar `r' = ``r''
}
end
*/
!cp pctrange.102.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
quietly pctrange tot_day
return list
!cp pctrange.103.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
!cp pctrange.104.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
!cp pctrange.105.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
/*
capture program drop pctrange
*! pctrange v1.0.3 CFBaum 22jul2007
program pctrange, rclass
version 10.1
syntax varlist(max=1 numeric) [, noPRINT]
local res range p7525 p9010 p9505 p9901
tempname `res'
quietly summarize `varlist', detail
scalar `range' = r(max) - r(min)
scalar `p7525' = r(p75) - r(p25)
scalar `p9010' = r(p90) - r(p10)
scalar `p9505' = r(p95) - r(p5)
scalar `p9901' = r(p99) - r(p1)
if "`print'" != "noprint" {
display as result _n "Percentile ranges for `varlist'"
display as txt "75-25: " `p7525'
display as txt "90-10: " `p9010'
display as txt "95-05: " `p9505'
display as txt "99-01: " `p9901'
display as txt "Range: " `range'
}
foreach r of local res {
return scalar `r' = ``r''
}
end
capture program drop pctrange
*! pctrange v1.0.3 CFBaum 22jul2007
program pctrange, rclass
version 10.1
syntax varlist(max=1 numeric) [if] [in] [, noPRINT]
marksample touse
quietly count if `touse'
if `r(N)' == 0 {
error 2000
}
local res range p7525 p9010 p9505 p9901
tempname `res'
quietly summarize `varlist' if `touse', detail
scalar `range' = r(max) - r(min)
scalar `p7525' = r(p75) - r(p25)
scalar `p9010' = r(p90) - r(p10)
scalar `p9505' = r(p95) - r(p5)
scalar `p9901' = r(p99) - r(p1)
if "`print'" != "noprint" {
display as result _n "Percentile ranges for `varlist', N = `r(N)'"
display as txt "75-25: " `p7525'
display as txt "90-10: " `p9010'
display as txt "95-05: " `p9505'
display as txt "99-01: " `p9901'
display as txt "Range: " `range'
}
foreach r of local res {
return scalar `r' = ``r''
}
return scalar N = r(N)
return local var `varlist'
end
*/
summarize percap, meanonly
pctrange tot_day if percap > r(mean) & !missing(percap)
!cp pctrange.106.ado pctrange.ado
program drop _all
which pctrange
type pctrange.ado
/*
capture program drop pctrange
*! pctrange v1.0.4 CFBaum 22jul2007
program pctrange, rclass
version 10.1
syntax varlist(min=1 numeric) [if] [in] [, noPRINT FORmat(passthru) MATrix(string)]
marksample touse
quietly count if `touse'
if `r(N)' == 0 {
error 2000
}
local nvar : word count `varlist'
if `nvar' == 1 {
local res range p7525 p9010 p9505 p9901
tempname `res'
quietly summarize `varlist' if `touse', detail
scalar `p7525' = r(p75) - r(p25)
scalar `p9010' = r(p90) - r(p10)
scalar `p9505' = r(p95) - r(p5)
scalar `p9901' = r(p99) - r(p1)
scalar `range' = r(max) - r(min)
if "`print'" != "noprint" {
display as result _n "Percentile ranges for `varlist', N = `r(N)'"
display as txt "75-25: " `p7525'
display as txt "90-10: " `p9010'
display as txt "95-05: " `p9505'
display as txt "99-01: " `p9901'
display as txt "Range: " `range'
}
foreach r of local res {
return scalar `r' = ``r''
}
return scalar N = r(N)
}
else {
tempname rmat
matrix `rmat' = J(`nvar',5,.)
local i 0
foreach v of varlist `varlist' {
local ++i
quietly summarize `v' if `touse', detail
matrix `rmat'[`i', 1] = r(p75) - r(p25)
matrix `rmat'[`i', 2] = r(p90) - r(p10)
matrix `rmat'[`i', 3] = r(p95) - r(p5)
matrix `rmat'[`i', 4] = r(p99) - r(p1)
matrix `rmat'[`i', 5] = r(max) - r(min)
local rown "`rown' `v'"
}
matrix colnames `rmat' = P75-P25 P90-P10 P95-P05 P99-P01 Range
matrix rownames `rmat' = `rown'
if "`print'" != "noprint" {
local form ", noheader"
if "`format'" != "" {
local form "`form' `format'"
}
matrix list `rmat' `form'
}
if "`matrix'" != "" {
matrix `matrix' = `rmat'
}
return matrix rmat = `rmat'
}
return local varname `varlist'
end
*/
pctrange regday specneed bilingua occupday tot_day tchratio, form(%9.2f)
pctrange regday specneed bilingua occupday tot_day tchratio, mat(MCAS) noprint
outtable using MCAS, mat(MCAS) caption("MCAS percentile ranges") format(%9.2f) nobox replace
/*
capture program drop pctrange
*! pctrange v1.0.6 CFBaum 22jul2007
program pctrange, rclass byable(recall)
version 10.1
syntax varlist(min=1 numeric ts) [if] [in] [, noPRINT FORmat(passthru) MATrix(string)]
marksample touse
quietly count if `touse'
if `r(N)' == 0 {
error 2000
}
local nvar : word count `varlist'
if `nvar' == 1 {
local res range p7525 p9010 p9505 p9901
tempname `res'
quietly summarize `varlist' if `touse', detail
scalar `range' = r(max) - r(min)
scalar `p7525' = r(p75) - r(p25)
scalar `p9010' = r(p90) - r(p10)
scalar `p9505' = r(p95) - r(p5)
scalar `p9901' = r(p99) - r(p1)
if "`print'" != "noprint" {
display as result _n "Percentile ranges for `varlist', N = `r(N)'"
display as txt "75-25: " `p7525'
display as txt "90-10: " `p9010'
display as txt "95-05: " `p9505'
display as txt "99-01: " `p9901'
display as txt "Range: " `range'
}
foreach r of local res {
return scalar `r' = ``r''
}
return scalar N = r(N)
}
else {
tempname rmat
matrix `rmat' = J(`nvar',5,.)
local i 0
foreach v of varlist `varlist' {
local ++i
quietly summarize `v' if `touse', detail
matrix `rmat'[`i',1] = r(max) - r(min)
matrix `rmat'[`i',2] = r(p75) - r(p25)
matrix `rmat'[`i',3] = r(p90) - r(p10)
matrix `rmat'[`i',4] = r(p95) - r(p5)
matrix `rmat'[`i',5] = r(p99) - r(p1)
local rown "`rown' `v'"
}
matrix colnames `rmat' = Range P75-P25 P90-P10 P95-P05 P99-P01
matrix rownames `rmat' = `rown'
if "`print'" != "noprint" {
local form ", noheader"
if "`format'" != "" {
local form "`form' `format'"
}
matrix list `rmat' `form'
}
if "`matrix'" != "" {
matrix `matrix' = `rmat'
}
return matrix rmat = `rmat'
}
return local var `varlist'
end
*/
summarize avgsalry, meanonly
generate byte highsal = avgsalry > r(mean) & !missing(avgsalry)
label define sal 0 low 1 high
label val highsal sal
tabstat avgsalry, by(highsal) stat(mean N)
bysort highsal: pctrange regday specneed bilingua occupday tot_day tchratio
!cp _gpct9010.100.ado _gpct9010.ado
program drop _all
which _gpct9010
type _gpct9010.ado
/*
capture program drop _gpct9010
*! _gpct9010 v1.0.0 CFBaum 30jul2007
program _gpct9010
version 10.1
syntax newvarname =/exp [if] [in]
tempvar touse
mark `touse' `if' `in'
quietly summarize `exp' if `touse', detail
quietly generate `typlist' `varlist' = r(p90) - r(p10) if `touse'
end
capture program drop _gpct9010
*! _gpct9010 v1.0.1 CFBaum 30jul2007
program _gpct9010
version 10.1
syntax newvarname =/exp [if] [in] [, *]
tempvar touse p90 p10
mark `touse' `if' `in'
quietly {
egen double `p90' = pctile(`exp') if `touse', `options' p(90)
egen double `p10' = pctile(`exp') if `touse', `options' p(10)
generate `typlist' `varlist' = `p90' - `p10' if `touse'
}
end
*/
!cp _gpct9010.101.ado _gpct9010.ado
program drop _all
which _gpct9010
type _gpct9010.ado
sysuse auto, clear
bysort rep78 foreign: egen pctrange = pct9010(price)
chelp pctrange
!cp mynormal_lf.100.ado mynormal_lf.ado
program drop _all
which mynormal_lf
type mynormal_lf.ado
/*
capt program drop mynormal_lf
program mynormal_lf
version 10.1
args lnf mu sigma
quietly replace `lnf' = ln(normalden($ML_y1, `mu', `sigma'))
end
*/
!cp mynormal.100.ado mynormal.ado
program drop _all
which mynormal
type mynormal.ado
/*
capture program drop mynormal Replay Estimate
program mynormal
version 10.1
if replay() {
if ("`e(cmd)'" != "mynormal") error 301
Replay `0'
}
else Estimate `0'
end
program Replay
syntax [, Level(cilevel) ]
ml display, level(`level')
end
program Estimate, eclass sortpreserve
syntax varlist [if] [in] [, vce(passthru) Level(cilevel) * ]
mlopts mlopts, `options'
gettoken lhs rhs: varlist
marksample touse
ml model lf mynormal_lf (mu: `lhs' = `rhs') /sigma ///
if `touse', `vce' `mlopts' maximize
ereturn local cmd "mynormal"
Replay, level(`level')
end
*/
sysuse auto,clear
mynormal price mpg weight turn
mynormal, level(90)
test weight = 5
predict double pricehat, xb
summarize price pricehat
type nlces.ado
/*
capture program drop nlces
program nlces
version 10.1
syntax varlist(min=3 max=3) if, at(name)
tokenize `varlist'
args logoutput K L
tempname b0 rho delta
tempvar kterm lterm
scalar `b0' = `at'[1, 1]
scalar `rho' = `at'[1, 2]
scalar `delta' = `at'[1, 3]
gen double `kterm' = `delta' * `K'^(-(`rho')) `if'
gen double `lterm' = (1 - `delta') *`L'^(-(`rho')) `if'
replace `logoutput' = `b0' - 1 / `rho' * ln(`kterm' + `lterm') `if'
end
*/
* webuse production, clear
use production, clear
nl ces @ lnoutput capital labor, parameters(b0 rho delta) ///
initial(b0 0 rho 1 delta 0.5)
nlcom (sigma: 1 / (1 + [rho]_b[_cons]))
// generate `y1' = medage + invnorm(uniform()) * 0.05 * zmu
// generate `y2' = medage + invnorm(uniform()) * 0.05 * z_factor
program drop _all
which mcsimul
type mcsimul.ado
/*
capt program drop mcsimul
program mcsimul, rclass
version 10.1
tempvar y1 y2
generate `y1' = drate + invnorm(uniform()) * 0.05 * zmu
generate `y2' = drate + invnorm(uniform()) * 0.05 * z_factor
ttest `y1' = 80
return scalar p1 = r(p)
ttest `y2' = 80
return scalar p2 = r(p)
end
*/
* webuse census2, clear
set seed 20070731
use census2, clear
generate z_factor = 10 * region
summarize z_factor, meanonly
scalar zmu = r(mean)
quietly simulate p1=r(p1) p2=r(p2), ///
saving(mcsimul,replace) nodots reps(1000): mcsimul drate, mu(80)
use mcsimul, clear
generate R5pc_1 = (p1 < 0.05)
generate R5pc_2 = (p2 < 0.05)
summarize