Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: st: egen and recode, from summary statistics, zero values [SEC:


From   Christopher Baum <[email protected]>
To   "[email protected]" <[email protected]>
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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index