[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
rraciborski@gmail.com |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Code |

Date |
Tue, 22 Jul 2008 15:48:53 -0400 |

ana, here it goes, it is not perfect but will get you started. copy the command into a text file and save as poverty.ado. on your data it returns: . poverty inc 228 5 Summary of income for 11 households above and below the poverty level of 228 Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- inc | 11 223.4002 27.9786 167.7384 252.6725 rafal ***************************** start of poverty.ado ******************************* *! program to calculate mean income around a given poverty level *! syntax: poverty incomeVar povertyLevel window *! example: poverty gdppc 12000 500 program define poverty, sortpreserve version 9.2 args inc inclev n /* inc = income variable inclev = poverty level (number) n = window (how many incomes above and below poverty level to include) */ tempvar diff match id sort `inc' gen `id' = _n gen byte `match' = 0 gen `diff' = abs(`inc' - `inclev') qui summ `diff' qui replace `match' = 1 if `diff' == r(min) qui count if `match'==1 if r(N) > 1 { di as err "More than one observation matches the poverty level" exit } qui summ `id' if `match' == 1 local obs = r(mean) if (`obs' - `n' <= 0) | (`obs' + `n' > _N) { di as err "There are not enough observations around the poverty level" exit } di di as res "Summary of income for " 2*`n'+1 " households above and below the poverty level of `inclev'" summ `inc' if (_n >= `obs' - `n') & (_n <= `obs' + `n') end exit ***************************** end of poverty.ado ******************************* On 7/22/08, Ana R. Rios <arorigal@yahoo.com> wrote: > Dear Stata users, > > Could someone suggest a code that will perform the following? > - I have defined a poverty level based on income per capita (incpc). I > would like to perform calculations on x number of households above/below > poverty. > > Here is an example: lets assume that the poverty level is an income per > capita equal to 228.22. I would like to calculate the mean income per > capita for a total sample of 11 households: 5 households above poverty, 5 > households below povery and the household at the poverty level. That is, > the mean income per capita for observations 8 to 18. > > obs househol incpc > 1 18109 15.87111 > 2 19705 52.32142 > 3 37503 75 > 4 25309 80 > 5 33520 91.14099 > 6 22905 100 > 7 4113 150 > 8 37520 167.7384 > 9 33102 190 > 10 28614 192.205 > 11 28504 227.3124 > 12 37616 227.3575 > 13 37620 228.22 > 14 33518 235.8528 > 15 33315 236.0431 > 16 4205 250 > 17 5210 250 > 18 23814 252.6725 > 19 28506 256.8579 > 20 30912 265 > > > Thank you for your time. > > Regards, > Ana Rios > > > > > * > * 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/ > * * 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/

**References**:**st: Code***From:*"Ana R. Rios" <arorigal@yahoo.com>

- Prev by Date:
**Re: st: Code** - Next by Date:
**Re: st: Re: importing spss data** - Previous by thread:
**Re: st: Code** - Next by thread:
**st: RE: Code** - Index(es):

© Copyright 1996–2017 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |