JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for ALLSTAT Archives


ALLSTAT Archives

ALLSTAT Archives


allstat@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

ALLSTAT Home

ALLSTAT Home

ALLSTAT  2005

ALLSTAT 2005

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

solution to vector and loop problem in spss

From:

Ann E Fitzmaurice <[log in to unmask]>

Reply-To:

Ann E Fitzmaurice <[log in to unmask]>

Date:

Thu, 2 Jun 2005 12:07:43 +0100

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (169 lines)

My thanks to all who replied , the solution to my problem is given below
(thanks cor), all that remains is to rename the 5 new variables and to put
in the labels

The reason for a dummy variable for each of the categories as I want to use
the full set of dummy variables, I realize that if I was using regression
techniques then one of the variables would be redundant and would be classed
as the reference - 

Thanks again

Regards

Ann


Thanks again-----Original Message-----
From: Stolk, Cor [mailto:[log in to unmask]] 
Sent: 02 June 2005 11:52
To: Ann E Fitzmaurice
Subject: RE: vectors and creating dummy variables

Hi Ann,

the number of cases if irrelevant, but the number of groups of variables is,
of course.
The following syntax does work in SPSS 12:

vector V(5).
loop #I=1 to 5.
compute V(#I)=0.
if (FIRST=#I) V(#I)=1.
end loop.
execute.

First the vector of new variables is created; then each V(#I) is initialised
to 0, then conditional on FIRST the proper V is set to 1. If FIRST is
missing or outside the range 1..5, none is set to 1. The execute command
causes the transformations to be applied.

Cor Stolk
--------------------------------------------------------
dr C.Stolk
Centre for Research and Statistics (COS ; http://www.cos.rotterdam.nl )
Municipalty of Rotterdam
tel	+(31)10-4899535
fax	+(31)10-4899501
e-mail	[log in to unmask]




-----Oorspronkelijk bericht-----
Van: Ann E Fitzmaurice [mailto:[log in to unmask]]
Verzonden: donderdag 2 juni 2005 12:33
Aan: Stolk, Cor
Onderwerp: RE: vactors and creating dummy variables


Hi

I gave so few values as an example, there are over 10000 cases in the data
file
 Hence the use of vectors and loops, I will have to do this for a series of
variables

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/

 

-----Original Message-----
From: Stolk, Cor [mailto:[log in to unmask]] 
Sent: 02 June 2005 11:29
To: Ann E Fitzmaurice
Subject: RE: vactors and creating dummy variables

Hi Ann,

you might use this SPSS syntax:

numeric v1 v2 v3 v4 v5 (f1.0).
do if sysmis(first)).
+ compute v1=0.
+ compute v2=0.
+ compute v3=0.
+ compute v4=0.
+ compute v5=0.
else.
+ recode first (1=1)(else=0) into v1.
+ recode first (2=1)(else=0) into v2.
+ recode first (3=1)(else=0) into v3.
+ recode first (4=1)(else=0) into v4.
+ recode first (5=1)(else=0) into v5.
end if.


With so few values I don't think its worthwhile to look for more efficient
solutions like vectors.

Cor Stolk
--------------------------------------------------------
dr C.Stolk
Centre for Research and Statistics (COS ; http://www.cos.rotterdam.nl )
Municipalty of Rotterdam
tel	+(31)10-4899535
fax	+(31)10-4899501
e-mail	[log in to unmask]



-----Oorspronkelijk bericht-----
Van: A UK-based worldwide e-mail broadcast system mailing list
[mailto:[log in to unmask]]Namens Ann E Fitzmaurice
Verzonden: donderdag 2 juni 2005 12:19
Aan: [log in to unmask]
Onderwerp: vactors and creating dummy variables


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/

 

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager