Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: coding a categorical variable to a % continuous variable


From   Roger Newson <roger.newson@kcl.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: coding a categorical variable to a % continuous variable
Date   Sun, 13 Jun 2004 12:12:02 +0100

At 01:56 12/06/2004, Suzy wrote:
Hello,

I have a dichotomous variable (0=no ; 1=yes) that I would like to use in a scatter plot on the y axis as a continuous variable as a % variable.

For example: the x axis could be age and the y axis could be % smokers.

Can anyone help with this ?
You don't say what version of Stata you are using. However, if it is Stata 8, then you can use either -xcollapse- or -xcontract- (downloadable from SSC).

With -xcontract-, you can create a dataset with 1 observation per age group and smoking category and data on percent of smoking category within age group, and plot bthe percentages smoking, something like this:

xcontract smoker, by(agegp) norestore
scatter _percent agegp if smoker==1

With -xcollapse-, the program would be more like:

xcollapse (mean) smoker, by(agegp) norestore
replace smoker=smoker*100
lab var smoker "Percent smokers"
scatter smoker agegp

To find more about -xcollapse- and -xcontract-, type

ssc desc xcollapse
ssc desc xcontract

and to i8nstall them ,type

ssc inst xcontract
ssc inst xcollapse

If you want your percentages to have confidence limits, then you might like to use the -parmest- package, also downloadable from SSC, together with the official Stata -binreg- command.

I hope this helps.

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: roger.newson@kcl.ac.uk
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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