Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Christopher Baum <kit.baum@bc.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | re: st: egen and recode, from summary statistics, zero values [SEC: |
Date | Sun, 31 Jul 2011 17:42:27 -0400 |
<> Michelle said The end outcome is that I need a variable that contains either the actual added sugar intake, or half the non-zero minimum value if the added sugar intake is 0. +------------------+ | person ADD_SUG | |------------------| 1. | 1 0 | 2. | 2 20 | 3. | 3 30 | 4. | 4 0 | 5. | 5 0 | |------------------| 6. | 6 30 | 7. | 7 0 | 8. | 8 5 | 9. | 9 0 | 10. | 10 10 | +------------------+ su ADD_SUG if ADD_SUG>0 & !mi(ADD_SUG), mean g new_add_sugar = cond(ADD_SUG == 0, 0.5 * r(min), ADD_SUG) +-----------------------------+ | person ADD_SUG new_ad~r | |-----------------------------| 1. | 1 0 2.5 | 2. | 2 20 20 | 3. | 3 30 30 | 4. | 4 0 2.5 | 5. | 5 0 2.5 | |-----------------------------| 6. | 6 30 30 | 7. | 7 0 2.5 | 8. | 8 5 5 | 9. | 9 0 2.5 | 10. | 10 10 10 | +-----------------------------+ Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html An Introduction to Stata Programming | http://www.stata-press.com/books/isp.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/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/