help with selecting records

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

help with selecting records

thara vardhan-2
Dear list members

I have a data file which with variables personcni and Involvement Type and the file is structured as follows:

Sample dummy data:

PersonCNI                  InvolvementType
123                           VICTIM            
330                        VICTIM            
330                        PERSON OF INTEREST
330                        PERSON OF INTEREST
451                        PERSON OF INTEREST
555                        PERSON OF INTEREST
555                        PERSON OF INTEREST
666                        PERSON OF INTEREST
777                        PERSON OF INTEREST
777                        PERSON OF INTEREST
888                        PERSON OF INTEREST
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
9999                        VICTIM            
9999                              VICTIM            
9999                              PERSON OF INTEREST
9999                            VICTIM            

How do I select records where the person is a

a)        victim only
b)        POI only
c)        Both a victim and poi

In the first instance i am keeping it very simple with just these two variables without taking into account any date variables. All involvements were over 1 year period.  

I would be grateful if somebody could help select these records.

many thanks regards
thara

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information. If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well. No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.


Reply | Threaded
Open this post in threaded view
|

Re: help with selecting records

John F Hall

Is this how your data are stored?  If so you will be dealing with strings. It’s easier to work with numeric data, so I would recode the strings.  Probably best to create a new variable NEWTYPE first with something like:

 

File > new > syntax, then write:

 

DO IF (INVOLVEMENTTYPE = ‘VICTIM’ )

 NEWTYPE = 1)

  ELSE IF (INVOLVEMENTTYPE = PERSON OF INTEREST)

 NEWTYPE = 2

  ELSE IF (INVOLVEMENTTYPE = ‘VICTIM’ ) AND  (INVOLVEMENTTYPE = PERSON OF INTEREST)

 NEWTYPE = 3

END IF.

You can then use SELECT IF, but unless you precede it with a TEMPORARY command, you will lose the unselected cases if you save the file.  Thus:

 

TEMP .

SELECT IF (NEWVAR EQ 1) .

<ANALYSIS 1> .

TEMP .

SELECT IF (NEWVAR EQ 2) .

<ANALYSIS 2> .

 

TEMP .

SELECT IF (NEWVAR EQ 3) .

<ANALYSIS 3> .

 

I always work in lower case with abbreviated syntax.  There is relevant tutorial 2.3.1.1 Data transformations on my website under:

 

2.3: Data transformations

Selecting variables for analysis, changing the names of variables, changing the values of variables. Creating new variables from existing ones. Selecting cases for analysis as a transition from analysing one variable to analysing two or more variables.


 

John F Hall

 

[hidden email]

www.surveyresearch.weebly.com

 

 

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Thara Vardhan
Sent: 26 July 2011 08:09
To: [hidden email]
Subject: help with selecting records

 

Dear list members

I have a data file which with variables personcni and Involvement Type and the file is structured as follows:

Sample dummy data:

PersonCNI                  InvolvementType
123                           VICTIM            
330                        VICTIM            
330                        PERSON OF INTEREST
330                        PERSON OF INTEREST
451                        PERSON OF INTEREST
555                        PERSON OF INTEREST
555                        PERSON OF INTEREST
666                        PERSON OF INTEREST
777                        PERSON OF INTEREST
777                        PERSON OF INTEREST
888                        PERSON OF INTEREST
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
9999                        VICTIM            
9999                              VICTIM            
9999                              PERSON OF INTEREST
9999                            VICTIM            

How do I select records where the person is a

a)        victim only
b)        POI only
c)        Both a victim and poi

In the first instance i am keeping it very simple with just these two variables without taking into account any date variables. All involvements were over 1 year period.  

I would be grateful if somebody could help select these records.

many thanks regards
thara

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information. If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well. No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.

 

Reply | Threaded
Open this post in threaded view
|

Re: help with selecting records

Garry Gelade
In reply to this post by thara vardhan-2

Thera

 

Here’s one way (not elegant, but works).

 

data list LIST (",") /  PersonCNI (F4.0) InvolvementType (A6).

BEGIN DATA

123,VICTIM

330,VICTIM

330,POI

330,POI

451,POI

555,POI

555,POI

666,POI

777,POI

777,POI

888,POI

888,VICTIM

888,VICTIM

888,VICTIM

888,VICTIM

888,VICTIM

9999,VICTIM

9999,VICTIM

9999,POI

9999,VICTIM

END DATA.

 

 

RECODE InvolvementType ('VICTIM'=1) ('POI'=2) INTO involvecode.

 

AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= PersonCNI  /mintype=MIN(involvecode)  /maxtype=MAX(involvecode).

 

STRING persontype (A7).

if mintype = 1 & maxtype = 1 persontype = 'VICTIM'.

if mintype= 2 & maxtype=2 persontype = 'POI'.

if mintype=1 & maxtype=2 persontype = 'POI/VIC'.

EXECUTE.

 

LIST VARIABLES = personcni persontype.

 

PersonCNI persontype

 

    123   VICTIM

    330   POI/VIC

    330   POI/VIC

    330   POI/VIC

    451   POI

    555   POI

    555   POI

    666   POI

    777   POI

    777   POI

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

   9999   POI/VIC

   9999   POI/VIC

   9999   POI/VIC

   9999   POI/VIC

 

 

Now you can select in the normal way using the variable persontype.

 

Regards

 

Garry Gelade

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Thara Vardhan
Sent: 26 July 2011 07:09
To: [hidden email]
Subject: help with selecting records

 

Dear list members

I have a data file which with variables personcni and Involvement Type and the file is structured as follows:

Sample dummy data:

PersonCNI                  InvolvementType
123                           VICTIM            
330                        VICTIM            
330                        PERSON OF INTEREST
330                        PERSON OF INTEREST
451                        PERSON OF INTEREST
555                        PERSON OF INTEREST
555                        PERSON OF INTEREST
666                        PERSON OF INTEREST
777                        PERSON OF INTEREST
777                        PERSON OF INTEREST
888                        PERSON OF INTEREST
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
9999                        VICTIM            
9999                              VICTIM            
9999                              PERSON OF INTEREST
9999                            VICTIM            

How do I select records where the person is a

a)        victim only
b)        POI only
c)        Both a victim and poi

In the first instance i am keeping it very simple with just these two variables without taking into account any date variables. All involvements were over 1 year period.  

I would be grateful if somebody could help select these records.

many thanks regards
thara

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information. If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well. No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.

 

Reply | Threaded
Open this post in threaded view
|

Re: help with selecting records

joan casellas
In reply to this post by thara vardhan-2

Try this one.  Hope it helps.

 

DATA LIST list / PersonCNI *  InvolvementType (A255) .

BEGIN DATA

123 VICTIM            

330 VICTIM            

330 PERSON OF INTEREST

330 PERSON OF INTEREST

451 PERSON OF INTEREST

555 PERSON OF INTEREST

555 PERSON OF INTEREST

666 PERSON OF INTEREST

777 PERSON OF INTEREST

777 PERSON OF INTEREST

888 PERSON OF INTEREST

888 VICTIM            

888 VICTIM            

888 VICTIM            

888 VICTIM            

888 VICTIM            

9999 VICTIM            

9999 VICTIM            

9999 PERSON OF INTEREST

9999 VICTIM            

END DATA.

FRE PersonCNI InvolvementType.

 

SORT CASES BY PersonCNI .

CASESTOVARS

  /ID=PersonCNI

  /GROUPBY=VARIABLE.

 

 

COMPUTE VICTIM=0.

IF (InvolvementType.1="VICTIM" or InvolvementType.2="VICTIM" or InvolvementType.3="VICTIM" or InvolvementType.4="VICTIM" or InvolvementType.5="VICTIM" or

InvolvementType.6="VICTIM") VICTIM=1.

FRE VICTIM.

 

COMPUTE PERSON=0.

IF (InvolvementType.1="PERSON" or InvolvementType.2="PERSON" or InvolvementType.3="PERSON" or InvolvementType.4="PERSON" or InvolvementType.5="PERSON" or

InvolvementType.6="PERSON") PERSON=1.

FRE PERSON.

 

 

*************How do I select records where the person is a ************.

 

*************a)        victim only ********************************************.

 

COMPUTE SOLUS_VICTIM=$sysmis.

if (VICTIM=1 and PERSON=0) SOLUS_VICTIM=1.

fre SOLUS_VICTIM.

 

*************b)        POI only *************************************************.

 

COMPUTE SOLUS_PERSON=$sysmis.

if (VICTIM=0 and PERSON=1) SOLUS_PERSON=1.

fre SOLUS_PERSON.

 

 

************c)        Both a victim and poi *************************************

 

COMPUTE DUAL=$sysmis.

if (VICTIM=1 and PERSON=1) DUAL=1.

fre DUAL.

 

Thanks!

 

 

Joan Casellas Vega                                             

Media Research Analyst

Phone: +44 20 7593 1585                                     

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Thara Vardhan
Sent: 26 July 2011 07:09
To: [hidden email]
Subject: help with selecting records

 

Dear list members

I have a data file which with variables personcni and Involvement Type and the file is structured as follows:

Sample dummy data:

PersonCNI                  InvolvementType
123                           VICTIM            
330                        VICTIM            
330                        PERSON OF INTEREST
330                        PERSON OF INTEREST
451                        PERSON OF INTEREST
555                        PERSON OF INTEREST
555                        PERSON OF INTEREST
666                        PERSON OF INTEREST
777                        PERSON OF INTEREST
777                        PERSON OF INTEREST
888                        PERSON OF INTEREST
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
9999                        VICTIM            
9999                              VICTIM            
9999                              PERSON OF INTEREST
9999                            VICTIM            

How do I select records where the person is a

a)        victim only
b)        POI only
c)        Both a victim and poi

In the first instance i am keeping it very simple with just these two variables without taking into account any date variables. All involvements were over 1 year period.  

I would be grateful if somebody could help select these records.

many thanks regards
thara

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information. If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well. No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.

 

Reply | Threaded
Open this post in threaded view
|

Re: help with selecting records

John F Hall
In reply to this post by Garry Gelade

Same idea as mine, but there’s an error in my code: AND should be OR:

 

' DO IF (INVOLVEMENTTYPE = ‘VICTIM’ )

 NEWTYPE = 1)

  ELSE IF (INVOLVEMENTTYPE = PERSON OF INTEREST)

 NEWTYPE = 2

  ELSE IF (INVOLVEMENTTYPE = ‘VICTIM’ ) OR  (INVOLVEMENTTYPE = PERSON OF INTEREST)

 NEWTYPE = 3

END IF.

 

 

John F Hall

 

[hidden email]

www.surveyresearch.weebly.com

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Garry Gelade
Sent: 26 July 2011 10:55
To: [hidden email]
Subject: Re: help with selecting records

 

Thera

 

Here’s one way (not elegant, but works).

 

data list LIST (",") /  PersonCNI (F4.0) InvolvementType (A6).

BEGIN DATA

123,VICTIM

330,VICTIM

330,POI

330,POI

451,POI

555,POI

555,POI

666,POI

777,POI

777,POI

888,POI

888,VICTIM

888,VICTIM

888,VICTIM

888,VICTIM

888,VICTIM

9999,VICTIM

9999,VICTIM

9999,POI

9999,VICTIM

END DATA.

 

 

RECODE InvolvementType ('VICTIM'=1) ('POI'=2) INTO involvecode.

 

AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= PersonCNI  /mintype=MIN(involvecode)  /maxtype=MAX(involvecode).

 

STRING persontype (A7).

if mintype = 1 & maxtype = 1 persontype = 'VICTIM'.

if mintype= 2 & maxtype=2 persontype = 'POI'.

if mintype=1 & maxtype=2 persontype = 'POI/VIC'.

EXECUTE.

 

LIST VARIABLES = personcni persontype.

 

PersonCNI persontype

 

    123   VICTIM

    330   POI/VIC

    330   POI/VIC

    330   POI/VIC

    451   POI

    555   POI

    555   POI

    666   POI

    777   POI

    777   POI

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

    888   POI/VIC

   9999   POI/VIC

   9999   POI/VIC

   9999   POI/VIC

   9999   POI/VIC

 

 

Now you can select in the normal way using the variable persontype.

 

Regards

 

Garry Gelade

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Thara Vardhan
Sent: 26 July 2011 07:09
To: [hidden email]
Subject: help with selecting records

 

Dear list members

I have a data file which with variables personcni and Involvement Type and the file is structured as follows:

Sample dummy data:

PersonCNI                  InvolvementType
123                           VICTIM            
330                        VICTIM            
330                        PERSON OF INTEREST
330                        PERSON OF INTEREST
451                        PERSON OF INTEREST
555                        PERSON OF INTEREST
555                        PERSON OF INTEREST
666                        PERSON OF INTEREST
777                        PERSON OF INTEREST
777                        PERSON OF INTEREST
888                        PERSON OF INTEREST
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
888                        VICTIM            
9999                        VICTIM            
9999                              VICTIM            
9999                              PERSON OF INTEREST
9999                            VICTIM            

How do I select records where the person is a

a)        victim only
b)        POI only
c)        Both a victim and poi

In the first instance i am keeping it very simple with just these two variables without taking into account any date variables. All involvements were over 1 year period.  

I would be grateful if somebody could help select these records.

many thanks regards
thara

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information. If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well. No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.

 

Reply | Threaded
Open this post in threaded view
|

Re: help with selecting records

Bruce Weaver
Administrator
In reply to this post by thara vardhan-2
Hi Thara.  Here is another variation on some of the themes already posted.  You did not say you wanted to reduce the file to one row per ID, so I've left it in its original form.  If you DO want to reduce to one row per ID, you could have the AGGREGATE do that rather than add variables to the working file.


DATA LIST list / PersonCNI (f5.0)  InvolvementType (A25) .
BEGIN DATA
123 VICTIM            
330 VICTIM            
330 "PERSON OF INTEREST"
330 "PERSON OF INTEREST"
451 "PERSON OF INTEREST"
555 "PERSON OF INTEREST"
555 "PERSON OF INTEREST"
666 "PERSON OF INTEREST"
777 "PERSON OF INTEREST"
777 "PERSON OF INTEREST"
888 "PERSON OF INTEREST"
888 VICTIM            
888 VICTIM            
888 VICTIM            
888 VICTIM            
888 VICTIM            
9999 VICTIM            
9999 VICTIM            
9999 "PERSON OF INTEREST"
9999 VICTIM            
END DATA.

compute v = InvolvementType EQ "VICTIM".
compute i = InvolvementType EQ "PERSON OF INTEREST".

AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=PersonCNI
  /victim=MAX(v)
  /poi=MAX(i).

compute role = victim + poi*10.
format role (f1.0).
variable labels role "Role in the crime".
value labels role
  1 "Victim only"
 10 "POI only"
 11 "Victim and POI".

* Note that the file still has multiple cases per ID,
* so if you want a frequency distribution for individuals,
* you'll need to select one case per ID.

match files file=* / by PersonCNI / first = FirstRec.
temporary.
select if FirstRec.
freq role.

delete variables v to poi. /*delete unneeded variables.

HTH.

Thara Vardhan wrote
Dear list members

I have a data file which with variables personcni and Involvement Type and
the file is structured as follows:

Sample dummy data:

PersonCNI                  InvolvementType
123                        VICTIM
330                     VICTIM
330                     PERSON OF INTEREST
330                     PERSON OF INTEREST
451                     PERSON OF INTEREST
555                     PERSON OF INTEREST
555                     PERSON OF INTEREST
666                     PERSON OF INTEREST
777                     PERSON OF INTEREST
777                     PERSON OF INTEREST
888                     PERSON OF INTEREST
888                     VICTIM
888                     VICTIM
888                     VICTIM
888                     VICTIM
888                     VICTIM
9999                    VICTIM
9999                    VICTIM
9999                        PERSON OF INTEREST
9999                        VICTIM

How do I select records where the person is a

a)      victim only
b)      POI only
c)      Both a victim and poi

In the first instance i am keeping it very simple with just these two
variables without taking into account any date variables. All involvements
were over 1 year period.

I would be grateful if somebody could help select these records.

many thanks regards
thara
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information.  If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well.  No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).