creating a new variable

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

creating a new variable

Rodrigo Briceño
Dear SPSS listers. I have a database of households with information
about the amount of money received by bimester (variable= benefit) and
the institution were the money was sent for payments (variable=inst).
There is a mximum of 29 observations (29 bimesters) by household.
I need to create a new variable that for each household put me a value
indicating the institutions where they received money. There is a
maximum of 6  institutions where households can receive the money, so
for example HH1 received money in institutions 1 and 6, household 2 in
institutions 1 and 4, etc. In my new database with only households
appearing once I will have: hh1=16, hh2=14, where the numbers will
indicate the diff institutions where they received money.

Any idea about how to do that?
--

__________________________________________________________________

*Rodrigo Briceño*
Project Manager
Sanigest Internacional

+506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
+506  22-32-08-30                  *Fax
*+506  88-86-11-77*                  Celular**
*[hidden email] <mailto:[hidden email]>
www.sanigest.com <http://www.sanigest.com/>

MSN: [hidden email] <mailto:[hidden email]>
SKYPE: rbriceno1087

_____________________

This communication contains legal information which is privileged and
confidential. It is for the exclusive use of the address and
distribution, dissemination, copying or use by others is strictly
prohibited. If you have received this communication by error, please
delete the original message and e-mail us.


Esta comunicación contiene información legal privilegiada y confidencial
para el uso exclusivo del destinatario. La distribución, diseminación,
copia u otro uso por terceras personas es estrictamente prohibida. Si
usted ha recibido esta comunicación por error, le rogamos borrar el
mensaje original y comunicárnoslo a esta misma dirección.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Maguin, Eugene
Rodrigo,

Would you please post some example data showing the desired results, along
with your already posted problem description. I'm having trouble
understanding what you are wanting.

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Rodrigo Briceño
Sent: Tuesday, December 09, 2008 10:05 AM
To: [hidden email]
Subject: creating a new variable


Dear SPSS listers. I have a database of households with information
about the amount of money received by bimester (variable= benefit) and
the institution were the money was sent for payments (variable=inst).
There is a mximum of 29 observations (29 bimesters) by household.
I need to create a new variable that for each household put me a value
indicating the institutions where they received money. There is a
maximum of 6  institutions where households can receive the money, so
for example HH1 received money in institutions 1 and 6, household 2 in
institutions 1 and 4, etc. In my new database with only households
appearing once I will have: hh1=16, hh2=14, where the numbers will
indicate the diff institutions where they received money.

Any idea about how to do that?
--

__________________________________________________________________

*Rodrigo Briceño*
Project Manager
Sanigest Internacional

+506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
+506  22-32-08-30                  *Fax
*+506  88-86-11-77*                  Celular**
*[hidden email] <mailto:[hidden email]>
www.sanigest.com <http://www.sanigest.com/>

MSN: [hidden email] <mailto:[hidden email]>
SKYPE: rbriceno1087

_____________________

This communication contains legal information which is privileged and
confidential. It is for the exclusive use of the address and
distribution, dissemination, copying or use by others is strictly
prohibited. If you have received this communication by error, please
delete the original message and e-mail us.


Esta comunicación contiene información legal privilegiada y confidencial
para el uso exclusivo del destinatario. La distribución, diseminación,
copia u otro uso por terceras personas es estrictamente prohibida. Si
usted ha recibido esta comunicación por error, le rogamos borrar el
mensaje original y comunicárnoslo a esta misma dirección.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Rodrigo Briceño
For a more clarifying description of my problem: what I want is to
create a new var that have the numbers (combined) of the institutions
where the households received payments.

Example:

HH BIM INST PAYM NEWVAR
1      1      1       100       16
1      2      1       100       16
1      3      6       100       16
1      4      6       100       16
2      1      1       100       12
2      2      1       100       12
2      3      2       100       12
2      4      2       100       12
3      1      1       100       1234
3      2      2       100       1234
3      3      3       100       1234
3      4      3       100       1234

best regards

__________________________________________________________________

*Rodrigo Briceño*
Project Manager
Sanigest Internacional

+506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
+506  22-32-08-30                  *Fax
*+506  88-86-11-77*                  Celular**
*[hidden email] <mailto:[hidden email]>
www.sanigest.com <http://www.sanigest.com/>

MSN: [hidden email] <mailto:[hidden email]>
SKYPE: rbriceno1087

_____________________

This communication contains legal information which is privileged and
confidential. It is for the exclusive use of the address and
distribution, dissemination, copying or use by others is strictly
prohibited. If you have received this communication by error, please
delete the original message and e-mail us.


Esta comunicación contiene información legal privilegiada y confidencial
para el uso exclusivo del destinatario. La distribución, diseminación,
copia u otro uso por terceras personas es estrictamente prohibida. Si
usted ha recibido esta comunicación por error, le rogamos borrar el
mensaje original y comunicárnoslo a esta misma dirección.



Gene Maguin wrote:

> Rodrigo,
>
> Would you please post some example data showing the desired results, along
> with your already posted problem description. I'm having trouble
> understanding what you are wanting.
>
> Gene Maguin
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Rodrigo Briceño
> Sent: Tuesday, December 09, 2008 10:05 AM
> To: [hidden email]
> Subject: creating a new variable
>
>
> Dear SPSS listers. I have a database of households with information
> about the amount of money received by bimester (variable= benefit) and
> the institution were the money was sent for payments (variable=inst).
> There is a mximum of 29 observations (29 bimesters) by household.
> I need to create a new variable that for each household put me a value
> indicating the institutions where they received money. There is a
> maximum of 6  institutions where households can receive the money, so
> for example HH1 received money in institutions 1 and 6, household 2 in
> institutions 1 and 4, etc. In my new database with only households
> appearing once I will have: hh1=16, hh2=14, where the numbers will
> indicate the diff institutions where they received money.
>
> Any idea about how to do that?
> --
>
> __________________________________________________________________
>
> *Rodrigo Briceño*
> Project Manager
> Sanigest Internacional
>
> +506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
> +506  22-32-08-30                  *Fax
> *+506  88-86-11-77*                  Celular**
> *[hidden email] <mailto:[hidden email]>
> www.sanigest.com <http://www.sanigest.com/>
>
> MSN: [hidden email] <mailto:[hidden email]>
> SKYPE: rbriceno1087
>
> _____________________
>
> This communication contains legal information which is privileged and
> confidential. It is for the exclusive use of the address and
> distribution, dissemination, copying or use by others is strictly
> prohibited. If you have received this communication by error, please
> delete the original message and e-mail us.
>
>
> Esta comunicación contiene información legal privilegiada y confidencial
> para el uso exclusivo del destinatario. La distribución, diseminación,
> copia u otro uso por terceras personas es estrictamente prohibida. Si
> usted ha recibido esta comunicación por error, le rogamos borrar el
> mensaje original y comunicárnoslo a esta misma dirección.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Art Kendall
In reply to this post by Rodrigo Briceño
see if this does what you want.
Open a new instance of SPSS.
Copy the syntax below.  Paste it into a syntax window.  Then run it.


* make up some data.
new file.
INPUT PROGRAM.
LOOP household=1 TO 100.
leave household.
COMPUTE N_payments =rnd( rv.uniform(.5,29.5)).
loop payment = 1 to N_payments.
leave N_payments.
compute institution = rnd( rv.uniform(.5,6.5)).
END CASE.
end loop.
END LOOP.
END FILE.
END INPUT PROGRAM.
FORMATS household (F5.0)n_payments (f2) payment (f2) institution (f1).
FREQUENCIES VARS= payment institution.
* end make up some data.
*  use something like this after bringing your data from the database
into SPSS.
do repeat used=used1 to used6/which_inst =1 to 6.
if institution eq which_inst  used=1.
end repeat.
sort cases by household.
dataset declare aggfile.
aggregate outfile=aggfile /break= household
 /used1 to used6 = sum(used1 to used6).
DATASET ACTIVATE aggfile.
formats used1 to used6 (f1).
string used_institutions (a6).
do repeat used = used1 to used6/which_inst =1 to 6.
if used gt 0 used_institutions = concat(rtrim(used_institutions),
string(which_inst,f1)).
end repeat.
frequencies vars = used_institutions.


Art Kendall
Social Research Consultants


* make up some data.
new file.
INPUT PROGRAM.
LOOP household=1 TO 100.
leave household.
COMPUTE N_payments =rnd( rv.uniform(.5,29.5)).
loop payment = 1 to N_payments.
leave N_payments.
compute institution = rnd( rv.uniform(.5,6.5)).
END CASE.

end loop.
END LOOP.
END FILE.
END INPUT PROGRAM.
FORMATS household (F5.0)n_payments (f2) payment (f2) institution (f1).
FREQUENCIES VARS= payment institution.
* end make up some data.
*  use something like this after bringing your data from the database
into SPSS.
do repeat used=used1 to used6/which_inst =1 to 6.
if institution eq which_inst  used=1.
end repeat.
sort cases by household.
dataset declare aggfile.
aggregate outfile=aggfile /break= household
 /used1 to used6 = sum(used1 to used6).
DATASET ACTIVATE aggfile.
formats used1 to used6 (f1).
string used_institutions (a6).
do repeat used = used1 to used6/which_inst =1 to 6.
if used gt 0 used_institutions = concat(rtrim(used_institutions),
string(which_inst,f1)).
end repeat.
frequencies vars = used_institutions.





Rodrigo Briceño wrote:

> Dear SPSS listers. I have a database of households with information
> about the amount of money received by bimester (variable= benefit) and
> the institution were the money was sent for payments (variable=inst).
> There is a mximum of 29 observations (29 bimesters) by household.
> I need to create a new variable that for each household put me a value
> indicating the institutions where they received money. There is a
> maximum of 6  institutions where households can receive the money, so
> for example HH1 received money in institutions 1 and 6, household 2 in
> institutions 1 and 4, etc. In my new database with only households
> appearing once I will have: hh1=16, hh2=14, where the numbers will
> indicate the diff institutions where they received money.
>
> Any idea about how to do that?
> --
>
> __________________________________________________________________
>
> *Rodrigo Briceño*
> Project Manager
> Sanigest Internacional
>
> +506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
> +506  22-32-08-30                  *Fax
> *+506  88-86-11-77*                  Celular**
> *[hidden email] <mailto:[hidden email]>
> www.sanigest.com <http://www.sanigest.com/>
>
> MSN: [hidden email] <mailto:[hidden email]>
> SKYPE: rbriceno1087
>
> _____________________
>
> This communication contains legal information which is privileged and
> confidential. It is for the exclusive use of the address and
> distribution, dissemination, copying or use by others is strictly
> prohibited. If you have received this communication by error, please
> delete the original message and e-mail us.
>
>
> Esta comunicación contiene información legal privilegiada y confidencial
> para el uso exclusivo del destinatario. La distribución, diseminación,
> copia u otro uso por terceras personas es estrictamente prohibida. Si
> usted ha recibido esta comunicación por error, le rogamos borrar el
> mensaje original y comunicárnoslo a esta misma dirección.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Albert-Jan Roskam
In reply to this post by Maguin, Eugene
Hi Rodrigo,

I concurr with Gene: it's not entirely clear what you want. But here's a shot in the dark (make sure you save your work first!):

sort cases by hh. /* sort by household.
casestovars /id = hh.
string money_pattern (a50).
compute money_pattern = concat (hh.1 to hh.??). /* replace ?? with no.

But do you really want a pattern of e.g. 6 1 to be different from 1 6?

Cheers & good luck!
Albert-Jan

--- On Tue, 12/9/08, Gene Maguin <[hidden email]> wrote:

> From: Gene Maguin <[hidden email]>
> Subject: Re: creating a new variable
> To: [hidden email]
> Date: Tuesday, December 9, 2008, 4:22 PM
> Rodrigo,
>
> Would you please post some example data showing the desired
> results, along
> with your already posted problem description. I'm
> having trouble
> understanding what you are wanting.
>
> Gene Maguin
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]]
> On Behalf Of
> Rodrigo Briceño
> Sent: Tuesday, December 09, 2008 10:05 AM
> To: [hidden email]
> Subject: creating a new variable
>
>
> Dear SPSS listers. I have a database of households with
> information
> about the amount of money received by bimester (variable=
> benefit) and
> the institution were the money was sent for payments
> (variable=inst).
> There is a mximum of 29 observations (29 bimesters) by
> household.
> I need to create a new variable that for each household put
> me a value
> indicating the institutions where they received money.
> There is a
> maximum of 6  institutions where households can receive the
> money, so
> for example HH1 received money in institutions 1 and 6,
> household 2 in
> institutions 1 and 4, etc. In my new database with only
> households
> appearing once I will have: hh1=16, hh2=14, where the
> numbers will
> indicate the diff institutions where they received money.
>
> Any idea about how to do that?
> --
>
> __________________________________________________________________
>
> *Rodrigo Briceño*
> Project Manager
> Sanigest Internacional
>
> +506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
> +506  22-32-08-30                  *Fax
> *+506  88-86-11-77*                  Celular**
> *[hidden email] <mailto:[hidden email]>
> www.sanigest.com <http://www.sanigest.com/>
>
> MSN: [hidden email] <mailto:[hidden email]>
> SKYPE: rbriceno1087
>
> _____________________
>
> This communication contains legal information which is
> privileged and
> confidential. It is for the exclusive use of the address
> and
> distribution, dissemination, copying or use by others is
> strictly
> prohibited. If you have received this communication by
> error, please
> delete the original message and e-mail us.
>
>
> Esta comunicación contiene información legal privilegiada
> y confidencial
> para el uso exclusivo del destinatario. La distribución,
> diseminación,
> copia u otro uso por terceras personas es estrictamente
> prohibida. Si
> usted ha recibido esta comunicación por error, le rogamos
> borrar el
> mensaje original y comunicárnoslo a esta misma dirección.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body
> text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the
> command
> INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body
> text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the
> command
> INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Maguin, Eugene
In reply to this post by Rodrigo Briceño
Rodrigo,

Thank you. The example was exactly what was needed. (By the way, the HH=4
record set has a consistency error in the newvar result.) Ok. In overview,
there two problems. One is to 'accumulate' the institution variable (INST)
across records with the same household ID (HH), and two, to 'spread' that
final, accumulated value across records within HH.

*  tested.
*  I assume INST is an A1 string.
String newvar(A6).
Do if ($casenum eq 1 or (hh ne lag(hh))).
+  compute substr(newvar,1,1)=inst.
+  compute #i=1.
Else.
+  compute newvar=lag(newvar).
+  compute #i=lag(#i).
+  do if (substr(newvar,#i,1) ne inst).
+     compute #i=#i+1.
+     compute substr(newvar,#i,1)=inst.
+  end if.
End if.
Execute.

Aggregate outfile=* mode=addvariables/break=hh/newvar1=last(newvar).
Execute.

Gene Maguin




>>Dear SPSS listers. I have a database of households with information
about the amount of money received by bimester (variable= benefit) and
the institution were the money was sent for payments (variable=inst).
There is a mximum of 29 observations (29 bimesters) by household.
I need to create a new variable that for each household put me a value
indicating the institutions where they received money. There is a
maximum of 6  institutions where households can receive the money, so
for example HH1 received money in institutions 1 and 6, household 2 in
institutions 1 and 4, etc. In my new database with only households
appearing once I will have: hh1=16, hh2=14, where the numbers will
indicate the diff institutions where they received money.

Example:

HH BIM INST PAYM NEWVAR
1      1      1       100       16
1      2      1       100       16
1      3      6       100       16
1      4      6       100       16
2      1      1       100       12
2      2      1       100       12
2      3      2       100       12
2      4      2       100       12
3      1      1       100       1234
3      2      2       100       1234
3      3      3       100       1234
3      4      3       100       1234

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Richard Ristow
In reply to this post by Rodrigo Briceño
At 10:04 AM 12/9/2008, Rodrigo Briceño wrote:
>I have a database of households with information
>about the amount of money received by bimester
>(variable= benefit) and the institution were the
>money was sent for payments (variable=inst)

and at 10:47 AM 12/9/2008 added:
>Example:
|-----------------------------|---------------------------|
|Output Created               |09-DEC-2008 13:21:41       |
|-----------------------------|---------------------------|
  HH BIM INST   PAYM NEWVAR

   1   1    1    100     16
   1   2    1    100     16
   1   3    6    100     16
   1   4    6    100     16
   2   1    1    100     12
   2   2    1    100     12
   2   3    2    100     12
   2   4    2    100     12
   3   1    1    100   1234
   3   2    2    100   1234
   3   3    3    100   1234
   3   4    3    100   1234

Number of cases read:  12    Number of cases listed:  12

>I want to create a new var that have the numbers
>(combined) of the institutions where the households received payments.

I still don't get this (but thank you, Gene, for requesting clarification).

Rodrigo, you wrote,

>I have information about the amount of money
>received by bimester (variable= BENEFIT) and the
>institution were the money was sent for payments (variable=INST)

I see variable "INST" in your example data, but not variable "BENEFIT".

I assume that your variable "NEWVAR" is what you
want to calculate. It is constant for any household. That often means using

AGGREGATE/MODE=ADDVARIABLES

but I can't see how the "NEWVAR" in your example
can be calculated from the other variables.

Gene, does this help either of us? Do you have more ideas?
=============================
APPENDIX: Test data, and code
=============================
DATA LIST LIST /
    HH    BIM    INST    PAYM    NEWVAR.
BEGIN DATA
    1      1      1       100    16
    1      2      1       100    16
    1      3      6       100    16
    1      4      6       100    16
    2      1      1       100    12
    2      2      1       100       12
    2      3      2       100       12
    2      4      2       100       12
    3      1      1       100       1234
    3      2      2       100       1234
    3      3      3       100       1234
    3      4      3       100       1234
END DATA.
FORMATS  HH BIM INST (F3)
          PAYM NEWVAR (F6).
LIST.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Rodrigo Briceño
In reply to this post by Art Kendall
Art, thanks for this magnificent work. I did it with this sintaxis and
the results were just the ones I wanted!
I will try the other two solutions provided by Gene and Richard, but
thanks to all of you...

__________________________________________________________________

*Rodrigo Briceño*
Project Manager
Sanigest Internacional

+506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
+506  22-32-08-30                  *Fax
*+506  88-86-11-77*                  Celular**
*[hidden email] <mailto:[hidden email]>
www.sanigest.com <http://www.sanigest.com/>

MSN: [hidden email] <mailto:[hidden email]>
SKYPE: rbriceno1087

_____________________

This communication contains legal information which is privileged and
confidential. It is for the exclusive use of the address and
distribution, dissemination, copying or use by others is strictly
prohibited. If you have received this communication by error, please
delete the original message and e-mail us.


Esta comunicación contiene información legal privilegiada y confidencial
para el uso exclusivo del destinatario. La distribución, diseminación,
copia u otro uso por terceras personas es estrictamente prohibida. Si
usted ha recibido esta comunicación por error, le rogamos borrar el
mensaje original y comunicárnoslo a esta misma dirección.



Art Kendall wrote:

> see if this does what you want.
> Open a new instance of SPSS.
> Copy the syntax below.  Paste it into a syntax window.  Then run it.
>
>
> * make up some data.
> new file.
> INPUT PROGRAM.
> LOOP household=1 TO 100.
> leave household.
> COMPUTE N_payments =rnd( rv.uniform(.5,29.5)).
> loop payment = 1 to N_payments.
> leave N_payments.
> compute institution = rnd( rv.uniform(.5,6.5)).
> END CASE.
> end loop.
> END LOOP.
> END FILE.
> END INPUT PROGRAM.
> FORMATS household (F5.0)n_payments (f2) payment (f2) institution (f1).
> FREQUENCIES VARS= payment institution.
> * end make up some data.
> *  use something like this after bringing your data from the database
> into SPSS.
> do repeat used=used1 to used6/which_inst =1 to 6.
> if institution eq which_inst  used=1.
> end repeat.
> sort cases by household.
> dataset declare aggfile.
> aggregate outfile=aggfile /break= household
> /used1 to used6 = sum(used1 to used6).
> DATASET ACTIVATE aggfile.
> formats used1 to used6 (f1).
> string used_institutions (a6).
> do repeat used = used1 to used6/which_inst =1 to 6.
> if used gt 0 used_institutions = concat(rtrim(used_institutions),
> string(which_inst,f1)).
> end repeat.
> frequencies vars = used_institutions.
>
>
> Art Kendall
> Social Research Consultants
>
>
> * make up some data.
> new file.
> INPUT PROGRAM.
> LOOP household=1 TO 100.
> leave household.
> COMPUTE N_payments =rnd( rv.uniform(.5,29.5)).
> loop payment = 1 to N_payments.
> leave N_payments.
> compute institution = rnd( rv.uniform(.5,6.5)).
> END CASE.
>
> end loop.
> END LOOP.
> END FILE.
> END INPUT PROGRAM.
> FORMATS household (F5.0)n_payments (f2) payment (f2) institution (f1).
> FREQUENCIES VARS= payment institution.
> * end make up some data.
> *  use something like this after bringing your data from the database
> into SPSS.
> do repeat used=used1 to used6/which_inst =1 to 6.
> if institution eq which_inst  used=1.
> end repeat.
> sort cases by household.
> dataset declare aggfile.
> aggregate outfile=aggfile /break= household
> /used1 to used6 = sum(used1 to used6).
> DATASET ACTIVATE aggfile.
> formats used1 to used6 (f1).
> string used_institutions (a6).
> do repeat used = used1 to used6/which_inst =1 to 6.
> if used gt 0 used_institutions = concat(rtrim(used_institutions),
> string(which_inst,f1)).
> end repeat.
> frequencies vars = used_institutions.
>
>
>
>
>
> Rodrigo Briceño wrote:
>> Dear SPSS listers. I have a database of households with information
>> about the amount of money received by bimester (variable= benefit) and
>> the institution were the money was sent for payments (variable=inst).
>> There is a mximum of 29 observations (29 bimesters) by household.
>> I need to create a new variable that for each household put me a value
>> indicating the institutions where they received money. There is a
>> maximum of 6  institutions where households can receive the money, so
>> for example HH1 received money in institutions 1 and 6, household 2 in
>> institutions 1 and 4, etc. In my new database with only households
>> appearing once I will have: hh1=16, hh2=14, where the numbers will
>> indicate the diff institutions where they received money.
>>
>> Any idea about how to do that?
>> --
>>
>> __________________________________________________________________
>>
>> *Rodrigo Briceño*
>> Project Manager
>> Sanigest Internacional
>>
>> +506  22-91-12-00 ext. 113  * Oficina* *Costa Rica*
>> +506  22-32-08-30                  *Fax
>> *+506  88-86-11-77*                  Celular**
>> *[hidden email] <mailto:[hidden email]>
>> www.sanigest.com <http://www.sanigest.com/>
>>
>> MSN: [hidden email] <mailto:[hidden email]>
>> SKYPE: rbriceno1087
>>
>> _____________________
>>
>> This communication contains legal information which is privileged and
>> confidential. It is for the exclusive use of the address and
>> distribution, dissemination, copying or use by others is strictly
>> prohibited. If you have received this communication by error, please
>> delete the original message and e-mail us.
>>
>>
>> Esta comunicación contiene información legal privilegiada y confidencial
>> para el uso exclusivo del destinatario. La distribución, diseminación,
>> copia u otro uso por terceras personas es estrictamente prohibida. Si
>> usted ha recibido esta comunicación por error, le rogamos borrar el
>> mensaje original y comunicárnoslo a esta misma dirección.
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>> [hidden email] (not to SPSSX-L), with no body text except the
>> command. To leave the list, send the command
>> SIGNOFF SPSSX-L
>> For a list of commands to manage subscriptions, send the command
>> INFO REFCARD
>>
>>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: creating a new variable

Richard Ristow
In reply to this post by Maguin, Eugene
At 01:11 PM 12/9/2008, Gene Maguin wrote:

>Thank you. The example was exactly what was needed. (By the way, the
>HH=4 record set has a consistency error in the newvar result.) Ok.
>In overview, there two problems. One is to 'accumulate' the
>institution variable (INST) across records with the same household
>ID (HH), and two, to 'spread' that final, accumulated value across
>records within HH.

Really nice job, Gene! As you'll see by my previous post, I
completely missed what his "NEWVAR" represented; took it as some kind
of numeric summary.

==============================
APPENDIX: Code for (successful)
test run of your code.
==============================
NEW FILE.
DATA LIST LIST /
    HH    BIM    INST     PAYM    WANTED
   (F4,   F4,    A1,      F6,     F6).
BEGIN DATA
    1      1      1       100    16
    1      2      1       100    16
    1      3      6       100    16
    1      4      6       100    16
    2      1      1       100    12
    2      2      1       100       12
    2      3      2       100       12
    2      4      2       100       12
    3      1      1       100       1234
    3      2      2       100       1234
    3      3      3       100       1234
    3      4      3       100       1234
END DATA.
FORMATS  HH BIM      (F3)
          PAYM NEWVAR (F6).
LIST.

*  .....   Gene Maguin's solution   ..... .
*  tested.
*  I assume INST is an A1 string.
String newvar(A6).
Do if ($casenum eq 1 or (hh ne lag(hh))).
+  compute substr(newvar,1,1)=inst.
+  compute #i=1.
Else.
+  compute newvar=lag(newvar).
+  compute #i=lag(#i).
+  do if (substr(newvar,#i,1) ne inst).
+     compute #i=#i+1.
+     compute substr(newvar,#i,1)=inst.
+  end if.
.  /**/  PRINT / '#i =', #i, '; inst =', inst, '; newvar=' newvar.
End if.


Aggregate
      outfile=* mode=addvariables
     /break=hh
     /newvar1=last(newvar).

LIST.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Multiple cases to single case

Khaneja, Gurvinder
In reply to this post by Art Kendall
Hi all,

I need to create single record file from multiple record file:

Original file:
ID     Term      Course       Grade
1        Fall02     Math101      A
1       Fall03      PSY101         B
1       Fall 04     Soc101          F
2       Fall02     Math101       A
2       Spr03    Math102        B
3       Fall02     Math101       A
3       Fall03    Soc101           C
3       Sum04   Soc102           B
3       Sum05   Psy102           C


I need the data reorganized as:

ID     Term       Course       Grade      Term2    Course2     Grade2       Term3     Course3    Grade3      Term4    Course4    Grade4
1        Fall02     Math101       A          Fall03      Psy101         B              Fall04      Soc101        F
2        Fall02     Math101       A          Spr03      Math102       B
3        Fall02    Math101        A          Fall03      Soc101          C             Sum04     Soc102       B               Sum05     Psy102         C

I appreciate help with the same.
Thanks
GK

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Multiple cases to single case

Daciuk, Tim
Take a look at the RESTRUCTURE facility, under the Data menu.  That should do what you want.

Tim Daciuk
Director, Worldwide Demo Resources
SPSS Inc.




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Khaneja, Gurvinder
Sent: Friday, February 13, 2009 8:37 PM
To: [hidden email]
Subject: Re: Multiple cases to single case

Hi all,

I need to create single record file from multiple record file:

Original file:
ID     Term      Course       Grade
1        Fall02     Math101      A
1       Fall03      PSY101         B
1       Fall 04     Soc101          F
2       Fall02     Math101       A
2       Spr03    Math102        B
3       Fall02     Math101       A
3       Fall03    Soc101           C
3       Sum04   Soc102           B
3       Sum05   Psy102           C


I need the data reorganized as:

ID     Term       Course       Grade      Term2    Course2     Grade2       Term3     Course3    Grade3      Term4    Course4    Grade4
1        Fall02     Math101       A          Fall03      Psy101         B              Fall04      Soc101        F
2        Fall02     Math101       A          Spr03      Math102       B
3        Fall02    Math101        A          Fall03      Soc101          C             Sum04     Soc102       B               Sum05     Psy102         C

I appreciate help with the same.
Thanks
GK

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Multiple cases to single case

Albert-Jan Roskam
In reply to this post by Khaneja, Gurvinder
Hi,

Untested:
sort cases by id.
casestovars / id = id.


Cheers!!
Albert-Jan


----- Original Message ----
From: "Khaneja, Gurvinder" <[hidden email]>
To: [hidden email]
Sent: Saturday, February 14, 2009 2:37:10 AM
Subject: Re: Multiple cases to single case

Hi all,

I need to create single record file from multiple record file:

Original file:
ID     Term      Course       Grade
1        Fall02     Math101      A
1       Fall03      PSY101         B
1       Fall 04     Soc101          F
2       Fall02     Math101       A
2       Spr03    Math102        B
3       Fall02     Math101       A
3       Fall03    Soc101           C
3       Sum04   Soc102           B
3       Sum05   Psy102           C


I need the data reorganized as:

ID     Term       Course       Grade      Term2    Course2     Grade2       Term3     Course3    Grade3      Term4    Course4    Grade4
1        Fall02     Math101       A          Fall03      Psy101         B              Fall04      Soc101        F
2        Fall02     Math101       A          Spr03      Math102       B
3        Fall02    Math101        A          Fall03      Soc101          C             Sum04     Soc102       B               Sum05     Psy102         C

I appreciate help with the same.
Thanks
GK

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Multiple cases to single case

Khaneja, Gurvinder
Thanks Albert.
I had to sort cases by id and term and then indexed it by term, I got the desired results.
GK

________________________________

From: Albert-jan Roskam [mailto:[hidden email]]
Sent: Sat 2/14/2009 12:42 PM
To: Khaneja, Gurvinder
Cc: [hidden email]
Subject: Re: Multiple cases to single case



Hi,

Untested:
sort cases by id.
casestovars / id = id.


Cheers!!
Albert-Jan


----- Original Message ----
From: "Khaneja, Gurvinder" <[hidden email]>
To: [hidden email]
Sent: Saturday, February 14, 2009 2:37:10 AM
Subject: Re: Multiple cases to single case

Hi all,

I need to create single record file from multiple record file:

Original file:
ID     Term      Course       Grade
1        Fall02     Math101      A
1       Fall03      PSY101         B
1       Fall 04     Soc101          F
2       Fall02     Math101       A
2       Spr03    Math102        B
3       Fall02     Math101       A
3       Fall03    Soc101           C
3       Sum04   Soc102           B
3       Sum05   Psy102           C


I need the data reorganized as:

ID     Term       Course       Grade      Term2    Course2     Grade2       Term3     Course3    Grade3      Term4    Course4    Grade4
1        Fall02     Math101       A          Fall03      Psy101         B              Fall04      Soc101        F
2        Fall02     Math101       A          Spr03      Math102       B
3        Fall02    Math101        A          Fall03      Soc101          C             Sum04     Soc102       B               Sum05     Psy102         C

I appreciate help with the same.
Thanks
GK

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD