[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: coding a categorical variable to a % continuous variable
At 01:56 12/06/2004, Suzy wrote:
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).
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 ?
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
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.
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
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
Opinions expressed are those of the author, not the institution.
* For searches and help try: