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: calculating proportions


From   Oliver Jones <[email protected]>
To   [email protected]
Subject   Re: st: calculating proportions
Date   Tue, 21 Feb 2012 11:01:17 +0100

Hello Ekaterina,

here is an little example. I hope it helps you.
Go through it very carefully. Even though it might not
be exactly what you need, it might point you in the right
direction.

*************** example code begins **************************
clear all
set obs 7

gen byte id = _n

gen byte sex = 1
replace sex = 0 in 4/7
label def lbl_sex 0 "male" 1 "female"
label values sex lbl_sex

gen int income = 7
replace income = 10 in 3
replace income = 0 in 4
replace income = 7 in 5
replace income = 9 in 6
replace income = 11 in 7

list


* So far is the setup of my little example.
* A crucial point is that I assume you have not to many
* different reportet levels of income, lets say 200.
* Otherwise I'm not too sure if this will work for you.

* Get  female statistics:
preserve
keep if sex == 1
contract income, percent(percent) cpercent(cum_percent)
list
tempfile fem_stats
save `fem_stats'
restore

* Get male income list and merge the female statistics:
keep if sex == 0
*bysort income: gen byte keepone = _n == 1
*keep if keepone == 1
merge m:1 income using `fem_stats'

sort income
list

* Now I think you can use carryforward on cum_percent,
* NOT on percent (as far as I understand your task!).

* carryforward is from SSC. Type -fintit carryforward-

* For your third variable just do a bit 1 minus calculations.


**************** example code ends ***************************
*
*   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