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


From   Ekaterina Hertog <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Re: calculating proportions
Date   Fri, 02 Mar 2012 18:53:14 +0000

Dear all,
Thank you very much all the advice, sorry if I appeared to abandon the thread, I had no internet for a week due to family illness. I have been working through the advice that Oliver and Nick offered and I am most grateful to both. I really like Nick's solution as it does not involve loops and hence works very quickly. I have played a bit with the code and this is the final version which produces the correct rankings

sysuse auto, clear
* foreign=22 domestic=52
contract mpg foreign
relrank mpg if foreign [fw=_freq] , ref(mpg if !foreign) gen(F)
la var F "proportion of domestic cars that have lower or equal to a given mileage value of a foreign car"
gen negmpg = -mpg
relrank negmpg if foreign [fw=_freq] , ref(negmpg if !foreign) gen(G)
la var G "proportion of domestic cars that have higher or equal to a given mileage value of a foreign car"
gen H = (G+F) - 1
la var H "proportion of domestic cars that have equal mileage to a given mileage value of a foreign car"
replace G = G - H
replace F = F - H
l mpg F G H

Thank you very much again,
Ekaterina
*
*   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