SPSS Statistics

 View Only
  • 1.  Transferring data from one case to another on same variable

    Posted Mon February 13, 2023 10:02 AM
    Hello! I
     am working on a big longitudinal dataset for my PhD project. I need to transfer some data from some students to other students within the same variable. I want to use syntax.
    So the idea is that I have students nested in teachers. The students filled out their age at W1 and then the teacher who was participating with them dropped out. The new teacher took over, so students received a new ID. But we did not ask them their age again at W2 when they participated with the new teacher. I now want to copy the age they give at W1 under their first ID to their new case at the second W2. My data is in a longformat, so waves nested in students. So the transfer happens at the same variable. -99 is used for missing
    My Data for example looks like this: CLASSID STUDID WAVE AGE
    1111 111111 1 8
    1111 111111 2 -99
    1112 111211 2 -99
     
    So student 111111 and 111112 are the same student and I want the age of 111111 on wave 1 to transfer to the age of 111211 on wave 2.
     
    I hope someone can help! I am using SPSS28.0.1.0


    ------------------------------
    Lian van Vemde
    ------------------------------


  • 2.  RE: Transferring data from one case to another on same variable

    IBM Champion
    Posted Mon February 13, 2023 10:10 AM
    Did you try the MATCH FILES approach I suggested on the Reddit site where you posted the same question?

    --





  • 3.  RE: Transferring data from one case to another on same variable

    Posted Mon April 15, 2024 10:39 AM

    I spent some time searching the internet for a solution. I'm posting my opinion here: I find it incredible that there is no easier way (than aggregate-match) to work within ranks in SPSS (for example to simply copy a value from one case to another case).



    ------------------------------
    Alexandre Pollien
    ------------------------------



  • 4.  RE: Transferring data from one case to another on same variable

    IBM Champion
    Posted Mon April 15, 2024 12:27 PM
    SPSS does not assume that the match data will fit in memory, but there is an equivalent to the Excel vlookup function that can be used if it will.  Here is a toy example from the SPSSINC TRANS doc (the lookup dataset could be the same as the main dataset).

    * Toy example using the SPSSINC TRANS extension command
    * The lookup table.
    data list free/ value(F8.0) akey(A1).
    begin data
    10 'a'
    20 'b'
    100 'z'
    end data.
    dataset name lookup.

    * The main dataset.
    data list free/x(f8.0) y(A2).
    begin data
    1 'a'
    2 'b'
    5 'a '
    10 ''
    1 'b'
    end data.
    dataset name main.

    spssinc trans result = resultcodealpha
    /initial "extendedTransforms.vlookup('akey', 'value', 'lookup')"
    /formula func(y).

    --





  • 5.  RE: Transferring data from one case to another on same variable

    Posted Thu February 16, 2023 02:20 PM

    I would create a temp file selecting the teacher who dropped from the study & then /table the data back in.



    ------------------------------
    Art Jack
    ------------------------------



  • 6.  RE: Transferring data from one case to another on same variable

    Posted Fri February 17, 2023 03:57 AM

    Thanks! I have rocoded the variables and managed to copy the data using syntax! 



    ------------------------------
    Lian van Vemde
    ------------------------------



  • 7.  RE: Transferring data from one case to another on same variable

    Posted Mon April 15, 2024 01:38 PM

    If you already have (or come to have) for each "recipient" case the known number of the "donor" case to copy a value from, you may use a ready macro of mine !KO_BORROW. Find on https://www.spsstools.net/en/KO-spssmacros/ in "Impute missing data" collection.



    ------------------------------
    Kirill Orlov
    ------------------------------