|
Hey everybody,
I am trying to write a small consistency check. I have variables which should only have the values 1 | 2 | 8 | 9. I would do the following: Use a loop within which an if-function would filter all values which are not within the allowed range. Then create a new dummy variable with the value 1 in case a wrong value is detected. These new dummy variables should be given the name of the old variable plus the extension "_d". List the original variables, the new dummy variables and the id, if the dummy variable has the value 1. Close the loop. I think this would work out quite well. The only problem is I am originally a STATA user, but now have to work with SPSS. In STATA I would write the following syntax: foreach x of varlist v10 v11 ...{ `x'_d = 1 if ((x<1) | ((x>2) & (x<8)) | (x>9)) list `x'_d x id if `x'_d==1 } My main problem is to translate the part >>`x'_d<< . I cannot find a command to add an extension to a varlist in a loop. Could someone please translate this into SPSS? Or does someone know a website supplying support for STATA into SPSS translation? Many thanks. Jara ===================== 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 |
|
Jara
How many cases are there?
How many variables are affected?
Send me more details.
Looks complicated; try this first to see which
cases fall outside your value range.
File
...New
...Syntax
write in the box:
count dummy = varx .... vary (lo thru
0, 3 thru 7, 10 thru hi) .
temp.
select if dummy gt 0
.
list ID .
Run
...All
or
[CTRL]R to
run the job.
Don't try in with the menus, it will take all
night!
If your variables are adjacent in the file you can
use varx to vary.
You can generate automatic varnames with
var1 to varn, but I don't think you can do this with varnames
ending in letters: I could be wrong.
Do you really need to keep the original
values? If you really need both sets of variables try
recode varx... vary (lo thru 0, 3 thru 7,
10 thru hi =1) (1,2,8,9 =0)
into newvarx...newvary
.
would be easier, especially if you change the all
varnames to end with a digit.
check out do repeat for doing
loops.
I have to go out now, but if you're still stuck,
I'll have another look later.
John Hall
----- Original Message -----
|
|
In reply to this post by Jara Kampmann
|
|
Administrator
|
In reply to this post by Jara Kampmann
One way to compute variable names by adding "_d" to existing variable names is via !CONCAT in the macro language. I wouldn't call myself a macro master, but by looking at some examples I have kept, I managed to cobble the following macro together. I think it does what you want. I won't be surprised if others post suggestions to clean up my code. And I expect this can also be done via Python. new file. dataset close all. data list list / v1 to v4 (4f2.0) . begin data 1 2 8 9 3 2 8 9 1 4 8 9 1 2 10 9 1 2 8 12 end data. list. * Define macro to check for invalid values, * and create flag variables where they are found . define !check (varlist !cmdend) . !let !flaglist = "" compute error_count = 0. !do !x !in(!varlist) !let !flag = !concat(!x,"_d") !let !flaglist = !concat(!flaglist,!flag," ") compute !flag = ((!x<1) | ((!x>2) & (!x<8)) | (!x>9)) . if !flag error_count = error_count + 1. execute. !doend temporary. select if error_count GT 0 . list !varlist !flaglist . !enddefine. * Call the macro. !check varlist = v1 v2 v3 v4 . * Now check that it works with other variable names . new file. dataset close all. data list list / a b c d (4f2.0) . begin data 1 2 8 9 3 2 8 9 1 4 8 9 1 2 10 9 1 2 8 12 end data. * Call the macro. !check varlist = a b c d .
--
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/). |
|
In reply to this post by Jara Kampmann
Hi Jara,
In SPSS, you can list the bad cases also in the following way. The advantage is that you avoid programming cycles. COMPUTE id = $casenum /* you can drop this two lines if there is already an ID */ . FORMATS id (f8). TEMPORARY /* you wish to delete the good cases temporary and list only bad ones */. * in the following, replace x4 with the last x-variable. COUNT NofGoodValues = x1 TO x4 (1, 2, 8, 9) /* how many good values are there in the row? */. SELECT IF NofGoodValues < 4 /*replace 4 with the number of variables x; it deletes good cases */. LIST id x1 TO x4 . Best regards, Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jara Kampmann Sent: Friday, October 02, 2009 4:32 PM To: [hidden email] Subject: STATA command into SPSS Hey everybody, I am trying to write a small consistency check. I have variables which should only have the values 1 | 2 | 8 | 9. I would do the following: Use a loop within which an if-function would filter all values which are not within the allowed range. Then create a new dummy variable with the value 1 in case a wrong value is detected. These new dummy variables should be given the name of the old variable plus the extension "_d". List the original variables, the new dummy variables and the id, if the dummy variable has the value 1. Close the loop. I think this would work out quite well. The only problem is I am originally a STATA user, but now have to work with SPSS. In STATA I would write the following syntax: foreach x of varlist v10 v11 ...{ `x'_d = 1 if ((x<1) | ((x>2) & (x<8)) | (x>9)) list `x'_d x id if `x'_d==1 } My main problem is to translate the part >>`x'_d<< . I cannot find a command to add an extension to a varlist in a loop. Could someone please translate this into SPSS? Or does someone know a website supplying support for STATA into SPSS translation? Many thanks. Jara ===================== 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 |
| Free forum by Nabble | Edit this page |
