Code

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

Code

MOUNKARA Yakoubou
Hello!Pls i need ia help.I have 18 variables MP01,MP02,....,MP18, they take
values from 0 to 7. I want to assign all 0 (zero) to the number that occurs
the most in each variable. example
MP01MP02 MP03............
0         1       1
2         0       0
2         5       3
2         4       1
7         4       0
2         0       0
0         0       1
6         4       3

For MP01 to replace 0 by 2
MP02 replace 0 by 4
MP03 replace 0 by 1

Sorry, I am not very good in english but i think you could get my ideas.



--
MOUNKARA Yakoubou
GIS/Data Base Manager
CI-DNPGCA
Centre d'Information du Dispositif National de Prévention et de Gestion des
Crises Alimentaires
Cell:+227 96 96 78 24
      +227 21 79 17 11
bur Tel: +227 20 72 32 75

====================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: Code

Art Kendall
If you are sure you want to substitute a central value across cases
rather than within cases, here are some ways to do this.
Keep in mind that there could be more than one mode.  If and when you
adapt the example syntax below, you will need to hand copy the modes
into the recode statement.
Using AGGREGATE you could use the median rather than the mean.

If these variables are intended to be used in summative scales it is
more conventional to "substitute" the mean with something like this.
compute attitude1 = mean.4(mp01, mp04, mp07, mp11, mp16).


new file.
data list list /MP01 MP02 MP03 (3f3).
begin data
0         1       1
2         0       0
2         5       3
2         4       1
7         4       0
2         0       0
0         0       1
6         4       3
end data.

missing values mp01 to mp03 (0).
frequencies variables= mp01 to mp03
  /format=notable /statistics = mode.
numeric xmp01 to xmp03 (f1).
recode mp01 (missing=2)(else=copy) into xmp01.
recode mp02 (missing=4)(else=copy) into xmp02.
recode mp03 (missing=1)(else=copy) into xmp03.
* if you have more than 1 variable that has the same mode you can use
list of variables
  on the input and output sides of the recode for example
  recode mp07 mp09 mp11 (missing=3)(else=copy) into xmp07 xmp09 xmp11.

list variables = xmp01 to xmp03.

compute constant=1.
aggregate outfile=* mode=addvariables /break=constant
 / xbar01 to xbar03 = mean(mp01 to mp03).
do repeat mp = mp01 to mp03 /ymp = ymp01 to ymp03/ xbar= xbar01 to xbar03.
do if missing(mp).
compute ymp = xbar.
else.
compute ymp=mp.
end if.
end repeat.
formats ymp01 to ymp03 (f5.2).
list variables= ymp01 to ymp03.


Art Kendall
Social Research Consultants

MOUNKARA Yakoubou wrote:

> Hello!Pls i need ia help.I have 18 variables MP01,MP02,....,MP18, they take
> values from 0 to 7. I want to assign all 0 (zero) to the number that occurs
> the most in each variable. example
> MP01MP02 MP03............
> 0         1       1
> 2         0       0
> 2         5       3
> 2         4       1
> 7         4       0
> 2         0       0
> 0         0       1
> 6         4       3
>
> For MP01 to replace 0 by 2
> MP02 replace 0 by 4
> MP03 replace 0 by 1
>
> Sorry, I am not very good in english but i think you could get my ideas.
>
>
>
>

=====================
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: Code

Spousta Jan
In reply to this post by MOUNKARA Yakoubou
Hi Mounkara,

Try this:

new file.
data list list /MP01 MP02 MP03 (3f3).
begin data
0         1       1
2         0       0
2         5       3
2         4       1
7         4       0
2         0       0
0         0       1
6         4       3
end data.
missing values mp01 to mp03 (0).

define mod_replace (!pos = !cmd).
* SPSS Macro for replacement of missing values in the columns by the modal values of respective columns.
* Input arguments: list of variables in the active file to be processed (do not use TO convention).
* Author: Jan Spousta 2008.

recode !1 (missing = sysmis).
compute sortorder = $casenum.
SAVE OUTFILE=mydata /COMPRESSED.

!do !var !in (!1).

DATASET DECLARE auxiliary.
temp.
select if not missing(!var) .
AGGREGATE /OUTFILE='auxiliary' /BREAK=!var /N_BREAK=N.

DATASET activate auxiliary.

SORT CASES BY N_BREAK (D) !var (a).
select if $casenum = 1.
compute repl = !var .
compute !var = $sysmis.
exe.

DATASET CLOSE mydata.
DATASET DECLARE mydata.
get file = mydata.
SORT CASES BY !var .
MATCH FILES /FILE=* /TABLE='auxiliary' /BY !var /DROP= N_BREAK .
if missing(!var) !var = repl.
EXECUTE.

MATCH FILES /FILE=* /DROP= repl.
SORT CASES BY sortorder .
SAVE OUTFILE=mydata /COMPRESSED.

DATASET CLOSE auxiliary.

!doend.
!enddefine.

mod_replace MP01 MP02 MP03 .

Hope this helps,

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of MOUNKARA Yakoubou
Sent: Thursday, October 02, 2008 12:17 PM
To: [hidden email]
Subject: Code

Hello!Pls i need ia help.I have 18 variables MP01,MP02,....,MP18, they take values from 0 to 7. I want to assign all 0 (zero) to the number that occurs the most in each variable. example
MP01MP02 MP03............
0         1       1
2         0       0
2         5       3
2         4       1
7         4       0
2         0       0
0         0       1
6         4       3

For MP01 to replace 0 by 2
MP02 replace 0 by 4
MP03 replace 0 by 1

Sorry, I am not very good in english but i think you could get my ideas.



--
MOUNKARA Yakoubou
GIS/Data Base Manager
CI-DNPGCA
Centre d'Information du Dispositif National de Prévention et de Gestion des Crises Alimentaires
Cell:+227 96 96 78 24
      +227 21 79 17 11
bur Tel: +227 20 72 32 75

=======
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



_____________
Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --

=====================
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