Original Message:
Sent: 1/29/2025 10:38:00 AM
From: Emi Wuk
Subject: RE: SPSS - last observation carried forward
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
------------------------------
Original Message:
Sent: Wed January 29, 2025 09:13 AM
From: Bruce Weaver
Subject: SPSS - last observation carried forward
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. BMJ Ment Health 2008;11:3-5.
https://mentalhealth.bmj.com/content/11/1/3.2
I hope this helps.
Cheers,
Bruce
------------------------------
Bruce Weaver
Original Message:
Sent: Mon January 27, 2025 02:30 PM
From: Emi Wuk
Subject: SPSS - last observation carried forward
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 score1 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
------------------------------