SPSS Statistics

 View Only
  • 1.  SPSS - last observation carried forward

    Posted 4 days ago

    I'm using SPSS to analyse my data for my thesis. In the Study we are checking whether the questionnaire score of the participants improves after 3 months. The participants are required to answer the questionnaire every 2nd week. The problem is, that not everyone answered the questionnaire regularly or stopped filling it out towards the end of the study. So I have to impute the missing the values. To impute the data I would like to use "last observation carried forward". My data is numerical. I unfortunately couldn't find good instructions online. Does anyone know how to do last observation carried forward with SPSS?

    Example:

    Below the "ID" is the the ID of the study participant and the "week # score" would be the score they achieve when filling out the questionnaire.

    ID   Baseline score    week 2 score    week 4 score    week 6 score    week 8 score     week 10 score
    1     19                   17               15             ...            ...               ...
    2     22                   20               19             18             ...               ...
    3     23                   21               20             17             ...               ...
    4     26                   24               23             ...            ...               ...
    5     21                   19               17             14               12              ...
    6     23                   21               19             ...            ...               ...
    7     21                   20               18             ...            ...               ... 
    8     24                   22               21             17             ...               ...
    9     23                   21               20             ...            ...               ...
    

    Wherever I have the "..." I would need to impute the values from the previous week (aka last observation carried forward). Is there a function that can be carried out to have the last value carried forward?

    I have no relevant code, error messages, and debugging logs.

    Thank you in advance!



    ------------------------------
    Emi Wuk
    ------------------------------


  • 2.  RE: SPSS - last observation carried forward

    Posted 3 days ago

    Hello Emi.  First, please note that last observation carried forward (LOCF) is generally considered a HORRIBLE way to deal with missing data.  More about that later. 

    Having said that, if I wanted to use LOCF on a wide file like the one you showed, I think I would use VECTOR and LOOP, like this:

    NEW FILE.
    DATASET CLOSE ALL.
    * Read in the sample data.
    * Use 999 in place of ..., and treat it as missing.
    DATA LIST LIST / ID (F2.0) baseline week2 week4 week6 week8 week10 (6F5.0).
    BEGIN DATA
    1     19   17  15  999  999  999
    2     22   20  19   18  999  999
    3     23   21  20   17  999  999
    4     26   24  23  999  999  999
    5     21   19  17   14   12  999
    6     23   21  19  999  999  999
    7     21   20  18  999  999  999 
    8     24   22  21   17  999  999
    9     23   21  20  999  999  999
    END DATA.
    MISSING VALUES baseline to week10 (999).
    * Implement LOCF--but note that it is a HORRIBLE method 
    * for dealing with missing data.
    * Rename the variables to make them work with VECTOR & LOOP.
    RENAME VARIABLES (baseline week2 to week10 = y0 y1 y2 y3 y4 y5).
    VECTOR y = y0 to y5.
    LOOP # = 2 to 6.
    IF MISSING(y(#)) y(#) = y(#-1).
    END LOOP.
    * Restore original names if you like.
    RENAME VARIABLES (y0 TO y5 = baseline week2 week4 week6 week8 week10).
    LIST.

    I hesitated to share that code, because as noted above LOCF is a HORRIBLE method for dealing with missing data.  You can find multiple articles and books that explain why you should avoid it.  Here is one such article:

    Streiner DL.  Missing data and the trouble with LOCF. 

    https://mentalhealth.bmj.com/content/11/1/3.2

    I hope this helps.

    Cheers,
    Bruce



    ------------------------------
    Bruce Weaver
    ------------------------------



  • 3.  RE: SPSS - last observation carried forward

    Posted 3 days ago

    Hi Bruce, 

    Wow, first of all thank you so much! Where exactly do I type in the code? ( the one I copied down below)

    VECTOR y = y0 to y5.
    LOOP # = 2 to 6.
    IF MISSING(y(#)) y(#) = y(#-1).
    END LOOP.

    Yes, I believe you that it is a HORRIBLE way of imputing missing values, but my supervisor for my thesis advised me to do it. Do you have any other suggestions for imputing data that is not too difficult,  that is doable with SPSS for a beginner in statistics? 

    Cheers, 

    Emi



    ------------------------------
    Emi Wuk
    ------------------------------



  • 4.  RE: SPSS - last observation carried forward

    Posted 3 days ago
    It strikes me that in essence this is a survival or censoring problem.  You might look in that literature for suggestions.


    --





  • 5.  RE: SPSS - last observation carried forward

    Posted 2 days ago

    Hello Emi.  It sounds as if you have been a point-and-click user to this point.  If so, I encourage you to learn how to use command syntax.  One relatively easy first step you can take in that direction is always exiting GUI dialogs via the PASTE button (rather than Okay).  See also the Learning Syntax page at spsstools.net, and pay attention to the Key Items section that lists several reasons why it is so important to use command syntax.

    https://spsstools.net/en/syntax/learning-syntax/ 

    I hope this helps.



    ------------------------------
    Bruce Weaver
    ------------------------------



  • 6.  RE: SPSS - last observation carried forward

    Posted 2 days ago

    Brian's suggestion is nice. Another approach is to first transform the data layout into a long format (you have a "wide" layout). 

    DATA LIST LIST (";")/id(F2) score_w1(F2) score_w2(F2) score_w3(F2) score_w4(F2) score_w5(F2).
    BEGIN DATA
        1;19;17;15;;
        2;22;20;19;18;
        3;23;21;20;17;
        4;26;24;23;;
        5;21;19;17;14;12
        6;23;21;19;;
        7;21;20;18;;
        8;24;22;21;17;
        9;23;21;20;;
    END DATA.

    *Change layout from a wide to a long format: in the menus, use Data/Restructure/Restructure selected variables into cases.
    VARSTOCASES
        /MAKE score_w FROM score_w1 score_w2 score_w3 score_w4 score_w5
        /KEEP=id
        /NULL=KEEP.

    *Fill in the blanks. Could also be entered through the menus with Transform/Compute Variable...
    IF id=LAG(id) AND SYSMIS(score_w) score_w=LAG(score_w).
    EXECUTE.

    *If needed, transform back to a wide format with Data/Restructure/Restructure cases intop variables.
    SORT CASES BY id .
    CASESTOVARS
        /ID=id
        /SEPARATOR=""
        /GROUPBY=VARIABLE.



    ------------------------------
    Robert Lundqvist
    ------------------------------