In which software do you want to do this ? Here are the codes to do this
in R (www.r-project.org) :
v <- factor( c(1,3,4), levels=1:5 )
m <- model.matrix( 1:length(v) ~ v -1 )
m <- cbind( First=v, m )
write.table(m, file="output.txt", sep="\t", quote=FALSE, row.names=F)
The results will be written as a tab delimited file called output.txt at
the current working directory (type in getwd() to find out).
You can read in the data using read.delim(), read.csv() etc. See the
manuals for more info.
Regards, Adai
On Thu, 2005-06-02 at 11:18 +0100, Ann E Fitzmaurice wrote:
> Hi
>
> I have a variable coded 1-5, I would like to create 5 dummy variables coded
> 1 for yes and 0 for no based on the first variable see below
>
> First v1 v2 v3 v4 v5
> 1 1 0 0 0 0
> 3 0 0 1 0 0
> 4 0 0 0 1 0
>
> I would prefer if there are no missing values , so if missing on the
> variable first all the other variables would be set to 0
>
> I have tried using vector and loop but am unable to get the results I want -
> has anyone ever done this
>
> Regards
>
> Ann
>
>
> Ann E Fitzmaurice
> Medical Statistician
>
> University of Aberdeen
> Department of Obstetrics & Gynaecology
> Aberdeen Maternity Hospital
> Cornhill Road, Aberdeen. AB25 2ZL
>
> Tel: +44 (0) 1224 553876
> Fax: +44 (0) 1224 553708
> e-mail: [log in to unmask]
> http://www.abdn.ac.uk/dugaldbairdcentre/
>
>
>
|