create variables

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

create variables

abdelrhman elmubarak
 

Hi

I have data of 3 variables ID , center and date  of visit … ID is unique

I want  to create more 3 variables only for those who visit center  A,  as below

id

center

date of visit

repeat visit for center A 

visit other center

lost customer

A

A

20090109

1st visit

 

 

A

A

20090319

yes

no

no

B

A

20090212

1st visit

 

 

B

C

20090401

no

yes

no

C

A

20090625

1st visit

 

 

C

C

20090731

no

no

yes

D

B

20090320

 

 

 

E

D

20090411

 

 

 

F

D

20090516

 

 

 

G

B

20090605

 

 

 

 

Thanks in advance

 

Abdulrahman Yousef Elmubark

 


Windows Live: Keep your friends up to date with what you do online.
Reply | Threaded
Open this post in threaded view
|

Re: create variables

Ruben Geert van den Berg
Dear Abdulrahman,
 
I did not quite understand what you mean by 'lost customer'. Why isn't person B a lost customer (for center A, that is)? I think the SPSS syntax below will create the other two variables. I hope this is at least part of what you were looking for.
 
Kind regards,
 
Ruben van den Berg
 
 
*Read in the data.
 
Data list free/id_2 center_2 visit_2 (3a8).
Begin data
A A 20090109
A A 20090319
B A 20090212
B C 20090401
C A 20090625
C C 20090731
D B 20090320
E D 20090411
F D 20090516
G B 20090605
End data.
 
*Make numeric variables of strings.
 
AUTORECODE
VARIABLES=id_2 center_2 /INTO id center.
 
*Make data variable of date.
 
comp #yyyy=num(sub(visit_2,1,4),f4).
comp #mm=num(sub(visit_2,5,2),f2).
comp #dd=num(sub(visit_2,7,2),f2).
compute visit= DATE.MDY(#mm,#dd,#yyyy).
for visit(date).
 
*Aggregate within person and center.
 
sor cas by id center.
agg
/out * mod add
/bre id center
/fre=n
/lastv=max(visit)
/firstv=min(visit).
exe.
 
*Aggregate within person.
 
agg
/out * mod add
/bre id
/vis_oth=sd(center).
exe.
 
*Create repeated visit variable.
 
comp rep_vis=0.
if center=1 and visit=firstv rep_vis=1.
if center ne 1 rep_vis=2.
if center=1 and visit ne firstv rep_vis=3.
exe.
 
*Label repeated visit variable.
 
var lab rep_vis 'Repeated visit to center A?'.
val lab rep_vis 1'First visit to center a' 2'No' 3'Repeated visit to center a'.
 
*Create 'visit other center' variable.
 
comp vis_other=0.
if vis_oth gt 0 vis_other=1.
exe.
 
*Label 'visit other center' variable.
 
var lab vis_other 'Did the respondent visit more than one center?'.
val lab vis_other 0 'Has visited only one center' 1'Has visited two or more centers'.
 
*Delete all variables except the relevant ones.
 
matc fil fil *
/kee id center visit rep_vis vis_other.
exe.




 



 

Date: Tue, 3 Nov 2009 08:23:54 +0000
From: [hidden email]
Subject: create variables
To: [hidden email]

 

Hi

I have data of 3 variables ID , center and date  of visit … ID is unique

I want  to create more 3 variables only for those who visit center  A,  as below

id

center

date of visit

repeat visit for center A 

visit other center

lost customer

A

A

20090109

1st visit

 

 

A

A

20090319

yes

no

no

B

A

20090212

1st visit

 

 

B

C

20090401

no

yes

no

C

A

20090625

1st visit

 

 

C

C

20090731

no

no

yes

D

B

20090320

 

 

 

E

D

20090411

 

 

 

F

D

20090516

 

 

 

G

B

20090605

 

 

 


 

Thanks in advance

 

Abdulrahman Yousef Elmubark

 


Windows Live: Keep your friends up to date with what you do online.

Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: create variables

abdelrhman elmubarak

Dear Ruben

Thank you  very much for your syntax …this exactly what I am looking for first tow variables.

For lost customer, Sorry  it is my problem I didn’t explain well .  I mean  if customer didn’t shows up again in any center after his first visit  .

What will happen if I removed customer C visit to  center C?  Will this help in explaining  lost customer.

Thanks again

 

Abdulrahman

 


 

Date: Tue, 3 Nov 2009 12:59:24 +0000
From: [hidden email]
Subject: Re: create variables
To: [hidden email]

Dear Abdulrahman,
 
I did not quite understand what you mean by 'lost customer'. Why isn't person B a lost customer (for center A, that is)? I think the SPSS syntax below will create the other two variables. I hope this is at least part of what you were looking for.
 
Kind regards,
 
Ruben van den Berg
 
 
*Read in the data.
 
Data list free/id_2 center_2 visit_2 (3a8).
Begin data
A A 20090109
A A 20090319
B A 20090212
B C 20090401
C A 20090625
C C 20090731
D B 20090320
E D 20090411
F D 20090516
G B 20090605
End data.
 
*Make numeric variables of strings.
 
AUTORECODEVARIABLES=id_2 center_2 /INTO id center.
 
*Make data variable of date.
 
comp #yyyy=num(sub(visit_2,1,4),f4).
comp #mm=num(sub(visit_2,5,2),f2).
comp #dd=num(sub(visit_2,7,2),f2).
compute visit= DATE.MDY(#mm,#dd,#yyyy).
for visit(date).
 
*Aggregate within person and center.
 
sor cas by id center.
agg
/out * mod add
/bre id center
/fre=n
/lastv=max(visit)
/firstv=min(visit).
exe.
 
*Aggregate within person.
 
agg
/out * mod add
/bre id
/vis_oth=sd(center).
exe.
 
*Create repeated visit variable.
 
comp rep_vis=0.
if center=1 and visit=firstv rep_vis=1.
if center ne 1 rep_vis=2.
if center=1 and visit ne firstv rep_vis=3.
exe.
 
*Label repeated visit variable.
 
var lab rep_vis 'Repeated visit to center A?'.
val lab rep_vis 1'First visit to center a' 2'No' 3'Repeated visit to center a'.
 
*Crea! te 'visit other center' variable.
 
comp vis_other=0.
if vis_oth gt 0 vis_other=1.
exe.
 
*Label 'visit other center' variable.
 
var lab vis_other 'Did the respondent visit more than one center?'.
val lab vis_other 0 'Has visited only one center' 1'Has visited two or more centers'.
 
*Delete all variables except the relevant ones.
 
matc fil fil *
/kee id center visit rep_vis vis_other.
exe.




 



 

Date: Tue, 3 Nov 2009 08:23:54 +0000
From: [hidden email]
Subject: create variables
To: [hidden email]

 

Hi

I have data of 3 variables ID , center and date  of visit … ID is unique

I want  to create more 3 variables only for those who visit center  A,  as below

id

center

date of visit

repeat visit for center A 

visit other center

lost customer

A

A

20090109

1st visit

 

 

A

A

20090319

yes

no

no

B

A

20090212

1st visit

 

 

B

C

20090401

no

yes

no

C

A

20090625

1st visit

 

 

C

C

20090731

no

no

yes

D

B

20090320

 

 

 

E

D

20090411

 

 

 

F

D

20090516

 

 

 

G

B

20090605

 

 

 


 

Thanks in advance

 

Abdulrahman Yousef Elmubark

 


Windows Live: Keep your friends up to date with what you do online.

Express yourself instantly with MSN Messenger! MSN Messenger

Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
Reply | Threaded
Open this post in threaded view
|

Re: create variables

Ruben Geert van den Berg
Dear Abdulrahman,
 
I'm sorry but I still don't really understand what you mean. Perhaps you could send more sample data (more cases, more patterns, less 'system missings') to further clarify?
 
Kind regards,
 
Ruben van den Berg




 



 

Date: Tue, 3 Nov 2009 13:46:44 +0000
From: [hidden email]
Subject: Re: create variables
To: [hidden email]

Dear Ruben

Thank you  very much for your syntax …this exactly what I am looking for first tow variables.

For lost customer, Sorry  it is my problem I didn’t explain well .  I mean  if customer didn’t shows up again in any center after his first visit  .

What will happen if I removed customer C visit to  center C?  Will this help in explaining  lost customer.

Thanks again

 

Abdulrahman

 


 

Date: Tue, 3 Nov 2009 12:59:24 +0000
From: [hidden email]
Subject: Re: create variables
To: [hidden email]

Dear Abdulrahman,
 
I did not quite understand what you mean by 'lost customer'. Why isn't person B a lost customer (for center A, that is)? I think the SPSS syntax below will create the other two variables. I hope this is at least part of what you were looking for.
 
Kind regards,
 
Ruben van den Berg
 
 
*Read in the data.
 
Data list free/id_2 center_2 visit_2 (3a8).
Begin data
A A 20090109
A A 20090319
B A 20090212
B C 20090401
C A 20090625
C C 20090731
D B 20090320
E D 20090411
F D 20090516
G B 20090605
End data.
 
*Make numeric variables of strings.
 
AUTORECODEVARIABLES=id_2 center_2 /INTO id center.
 
*Make data variable of date.
 
comp #yyyy=num(sub(visit_2,1,4),f4).
comp #mm=num(sub(visit_2,5,2),f2).
comp #dd=num(sub(visit_2,7,2),f2).
compute visit= DATE.MDY(#mm,#dd,#yyyy).
for visit(date).
 
*Aggregate within person and center.
 
sor cas by id center.
agg
/out * mod add
/bre id center
/fre=n
/lastv=max(visit)
/firstv=min(visit).
exe.
 
*Aggregate within person.
 
agg
/out * mod add
/bre id
/vis_oth=sd(center).
exe.
 
*Create repeated visit variable.
 
comp rep_vis=0.
if center=1 and visit=firstv rep_vis=1.
if center ne 1 rep_vis=2.
if center=1 and visit ne firstv rep_vis=3.
exe.
 
*Label repeated visit variable.
 
var lab rep_vis 'Repeated visit to center A?'.
val lab rep_vis 1'First visit to center a' 2'No' 3'Repeated visit to center a'.
 
*Crea! te 'visit other center' variable.
 
comp vis_other=0.
if vis_oth gt 0 vis_other=1.
exe.
 
*Label 'visit other center' variable.
 
var lab vis_other 'Did the respondent visit more than one center?'.
val lab vis_other 0 'Has visited only one center' 1'Has visited two or more centers'.
 
*Delete all variables except the relevant ones.
 
matc fil fil *
/kee id center visit rep_vis vis_other.
exe.




 



 

Date: Tue, 3 Nov 2009 08:23:54 +0000
From: [hidden email]
Subject: create variables
To: [hidden email]

 

Hi

I have data of 3 variables ID , center and date  of visit … ID is unique

I want  to create more 3 variables only for those who visit center  A,  as below

id

center

date of visit

repeat visit for center A 

visit other center

lost customer

A

A

20090109

1st visit

 

 

A

A

20090319

yes

no

no

B

A

20090212

1st visit

 

 

B

C

20090401

no

yes

no

C

A

20090625

1st visit

 

 

C

C

20090731

no

no

yes

D

B

20090320

 

 

 

E

D

20090411

 

 

 

F

D

20090516

 

 

 

G

B

20090605

 

 

 


 

Thanks in advance

 

Abdulrahman Yousef Elmubark

 


Windows Live: Keep your friends up to date with what you do online.

Express yourself instantly with MSN Messenger! MSN Messenger

Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.

Express yourself instantly with MSN Messenger! MSN Messenger