SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  How to randomize one case per patient?

    Posted Thu November 04, 2021 04:28 PM
    Dear all,

    I have a small data set consisting of 114 root filled teeth, 57 cases (painful root filled teeth) and 57 controls (non-painful root filled teeth). Ten research subjects  contribute with two painful teeth each. Now I want to randomize so every research subject only contribute with one tooth each.

    How do I do that in SPSS? I work with version 25.

    Best wishes,

    ------------------------------
    Jakob Sjögren
    ------------------------------

    #SPSSStatistics


  • 2.  RE: How to randomize one case per patient?

    Posted Thu November 04, 2021 04:37 PM
    Hi. I guess I would sort the cases by id and eliminate duplicate ids, that is,
    * I made up some data just for the example.
    
    DATA LIST FREE /id tooth.
    BEGIN DATA.
    1 1
    2 1
    2 1
    3 0
    4 0
    5 1
    5 0
    5 0
    END DATA.
    
    SORT CASES by id.
    COMPUTE drop=0.
    IF id=lag(id) drop=1.
    EXECUTE.
    SELECT IF NOT(drop).
    FREQ VAR id.
    ​

    Make sure ids only appear once.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: How to randomize one case per patient?

    Posted Thu November 04, 2021 04:48 PM
    Thank you so much sir!

    Best wishes,

    Jakob Sjögren

    ------------------------------
    Jakob Sjögren
    ------------------------------



  • 4.  RE: How to randomize one case per patient?

    Posted Thu November 04, 2021 04:48 PM
    Or - is there an data entry order bias, so that teeth within a patient aren't entered randomly?

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 5.  RE: How to randomize one case per patient?

    Posted Thu November 04, 2021 04:53 PM
    They could be entered in the order: 1) Right upper jaw 2) Left upper jaw 3) Left lower jaw 4) Right lower jaw.

    Any other suggestions?

    ------------------------------
    Jakob Sjögren
    ------------------------------



  • 6.  RE: How to randomize one case per patient?

    Posted Thu November 04, 2021 05:11 PM
    Yes. Probably using AGGREGATE, DO IF, and SAMPLE. I'll need a minute, I'm in the middle of something. I'll get back to you ASAP. Thanks for your patience!

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 7.  RE: How to randomize one case per patient?

    Posted Thu November 04, 2021 06:09 PM
    Edited by System Admin Fri January 20, 2023 04:50 PM
    Try this:

    DATASET CLOSE ALL.
    NEW FILE.
    DATA LIST FREE /id tooth.
    BEGIN DATA.
    1 1
    2 1
    2 2
    3 1
    4 1
    5 1
    5 2
    6 1
    6 2
    7 1
    8 1
    9 1
    9 2
    10 1
    END DATA.
    * Obviously, made up data. You start here and change to your own variable name for id.
    
    AGGREGATE /OUTFILE=* MODE ADDVARIABLES /BREAK=ID /NT=N.
    
    * Write out two temp files to a writeable location.
    FILE HANDLE Temp1 /NAME="/Users/rick/tmp/t1.sav".
    FILE HANDLE Temp2 /NAME="/Users/rick/tmp/t2.sav".
    
    DATASET NAME Original.
    
    TEMPORARY.
    SELECT IF NT=1.
    SAVE OUT Temp1.
    
    TEMPORARY.
    SELECT IF NT=2.
    SAVE OUT Temp2.
    
    SET SEED=5456432.
    
    GET FILE Temp2.
    COMPUTE random=UNIFORM(1).
    SORT CASES BY id random.
    COMPUTE keep=MOD($CASENUM,2).
    EXECUTE.
    SELECT IF keep.
    SAVE OUT Temp2.
    
    MATCH FILES FILE=Temp1 /FILE=Temp2 /DROP random keep /BY id.
    SAVE OUT Temp1.
    
    ERASE FILE Temp2.​
    I think that will do it. Sorry to take so long. Got a little busy for awhile. :)

    Temp1 file has your data, one per id, randomly chosen. Change the SET SEED value if you want.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 8.  RE: How to randomize one case per patient?

    Posted Fri November 05, 2021 04:15 AM
    Thank you so much Sir!
    I really appreciate your fast help.

    Respectfully,

    ------------------------------
    Jakob Sjögren
    ------------------------------