Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Ekaterina Hertog <ekaterina.hertog@sociology.ox.ac.uk> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
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) - 1la 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/