| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: re: yeo-johnson power transform
(1) copy boxcox.ado to yeojohnson.ado and change program name.
(2) to handle Yeo-Johnson of LHS only, copy boxco_l.ado to
yeojo_l.ado and alter yeojohnson.ado call appropriately.
(3) In yeojo_l.ado,
program define LHS
args todo b lnf
tempname theta ssq diffL /* theta is theta for Lhs */
tempvar err yt
scalar `theta' = `b'[1,1] /* this is theta */
scalar `diffL'=reldif( `theta', 0)
if `diffL'> 1e-10 {
qui gen double `yt' =( ( $ML_y1^`theta'-1)/`theta' )
}
else {
qui gen double `yt' = ln( $ML_y1 )
}
Last block of code should say something like
qui gen double `yt' = .
if `diffL'> 1e-10 {
qui replace `yt' =( ( ($ML_y1+1)^`theta'-1)/
`theta' ) if $ML_y1 >= 0
qui replace `yt' = ( ( (abs($ML_y1)+1)^(2*`theta')-1)/(2*`theta' )
if $ML_y1 < 0
}
else {
qui replace `yt' = ln( $ML_y1 )
}
per the formula given at http://rweb.stat.umn.edu/R/library/alr3/html/
powtran.html
The yeojohnson command should then be able to handle arbitrary "y"
values (check to see if boxcox.ado screens out negative values, and
if so remove that screen from the code).
Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/