I'm working examining the effect of a particular anti-gentrification policy in Berlin. I want to use a survival analysis to see if the amount of time it takes any area to progress to the next stage of gentrification out of five stages (ungentrified through gentrified), but a normal regression doesn't work here because some areas might stop gentrifying altogether, and thus have 0 or NA for the time to the next stage. I've tried using R's survival
and mstate
packages but haven't had much luck finding relevant literature for this sort of analysis, and I'm wondering if anyone has any suggestions on how best to go about this.
For some further context, here's some of the dataset I'm using, where gcode
is the final status in 2019, and tg0
:tg5
is the time it takes to get from stage 0 to 1, 1 to 2, and so on. As you can see, the 0.000
places represent censored data where an area never reached the next stage.
> head(data, n=20)
RAUMID gcode tg0 tg1 tg2 tg3 tg4 tg5
1 1011101 4 2.001 1.999 2.001 4.000 0.000 NA
2 1011102 5 0.999 4.000 4.000 2.001 1.999 5.002
3 1011103 2 0.999 12.000 0.000 0.000 0.000 NA
4 1011104 4 0.999 6.001 1.999 4.000 0.000 NA
5 1011105 4 0.999 4.000 2.001 9.999 0.000 NA
6 1011201 4 0.999 6.001 1.999 6.001 0.000 NA
7 1011202 4 0.999 2.001 1.999 6.001 0.000 NA
8 1011203 4 0.999 4.000 2.001 4.000 0.000 NA
9 1011204 4 0.999 6.001 1.999 2.001 0.000 NA
10 1011301 2 0.999 12.000 0.000 0.000 0.000 NA
11 1011302 1 0.999 0.000 0.000 0.000 0.000 NA
12 1011303 5 0.999 2.001 1.999 2.001 4.000 7.001
13 1011304 2 0.000 0.999 0.000 0.000 0.000 NA
14 1011305 4 0.999 8.000 6.001 1.999 0.000 NA
15 1011306 2 0.000 0.999 0.000 0.000 0.000 NA
16 1011401 2 2.001 1.999 0.000 0.000 0.000 NA
17 1011402 1 2.001 0.000 0.000 0.000 0.000 NA
18 1022101 4 0.000 0.999 4.000 4.000 0.000 NA
19 1022102 4 0.000 0.999 4.000 4.000 0.000 NA
20 1022103 2 0.000 11.001 0.000 0.000 0.000 NA
Creating dummy variables for whether an area has been censored or whether it was treated during the period when it transitioned from one stage to another has been no problem, but actually using survival analysis for this type of problem has been really tricky.
Edit: for some additional context, here is a sample of data from which I calculated tg0
through tg5
:
To provide some further context, stage 0 means not (yet) gentrifiable, and is calculated based on an area being above the 70th percentile in average sale prices for residential properties. While I went back and forth on whether these areas should simply be eliminated from the dataset entirely before continued categorization, I decided to include them as, theoretically, an area could be initially ungentrifiable but then decrease in value sufficiently over the course of 10 years to be gentrifiable.
> head(data, n=20)
RAUMID gcode0yr gcode1yr gcode2yr gcode3yr gcode4yr gcode5yr
1 1011101 2002-12-31 2004-12-31 2006-12-31 2008-12-31 2012-12-31 <NA>
2 1011102 2001-12-31 2002-12-31 2006-12-31 2010-12-31 2012-12-31 2014-12-31
3 1011103 2001-12-31 2002-12-31 2014-12-31 <NA> <NA> <NA>
4 1011104 2001-12-31 2002-12-31 2008-12-31 2010-12-31 2014-12-31 <NA>
5 1011105 2001-12-31 2002-12-31 2006-12-31 2008-12-31 2018-12-31 <NA>
6 1011201 2001-12-31 2002-12-31 2008-12-31 2010-12-31 2016-12-31 <NA>
7 1011202 2001-12-31 2002-12-31 2004-12-31 2006-12-31 2012-12-31 <NA>
8 1011203 2001-12-31 2002-12-31 2006-12-31 2008-12-31 2012-12-31 <NA>
9 1011204 2001-12-31 2002-12-31 2008-12-31 2010-12-31 2012-12-31 <NA>
10 1011301 2001-12-31 2002-12-31 2014-12-31 <NA> <NA> <NA>
11 1011302 2001-12-31 2002-12-31 <NA> <NA> <NA> <NA>
12 1011303 2001-12-31 2002-12-31 2004-12-31 2006-12-31 2008-12-31 2012-12-31
13 1011304 <NA> 2001-12-31 2002-12-31 <NA> <NA> <NA>
14 1011305 2001-12-31 2002-12-31 2010-12-31 2016-12-31 2018-12-31 <NA>
15 1011306 <NA> 2001-12-31 2002-12-31 <NA> <NA> <NA>
16 1011401 2002-12-31 2004-12-31 2006-12-31 <NA> <NA> <NA>
17 1011402 2002-12-31 2004-12-31 <NA> <NA> <NA> <NA>
18 1022101 <NA> 2001-12-31 2002-12-31 2006-12-31 2010-12-31 <NA>
19 1022102 <NA> 2001-12-31 2002-12-31 2006-12-31 2010-12-31 <NA>
20 1022103 <NA> 2001-12-31 2012-12-31 <NA> <NA> <NA>
Another edit: Here is the outcome of my data wrangling:
dataL %>% group_by(RAUMID) %>% head(n=10)
# A tibble: 10 x 6
# Groups: RAUMID [10]
RAUMID startTime endTime event treatment_starttime treatedduring
<dbl> <dbl> <dbl> <fct> <dbl> <dbl>
1 1011101 4 6.00 tg2 NA 0
2 1011102 2.00 6.00 tg2 NA 0
3 1011103 2.00 14.0 tg2 18.0 0
4 1011104 2.00 8 tg2 NA 0
5 1011105 2.00 6.00 tg2 NA 0
6 1011201 2.00 8 tg2 NA 0
7 1011202 2.00 4 tg2 NA 0
8 1011203 2.00 6.00 tg2 NA 0
9 1011204 2.00 8 tg2 NA 0
10 1011301 2.00 14.0 tg2 NA 0
> dataL %>% group_by(RAUMID) %>% filter(treatedduring == 1) %>% head(n=10)
# A tibble: 10 x 6
# Groups: RAUMID [10]
RAUMID startTime endTime event treatment_starttime treatedduring
<dbl> <dbl> <dbl> <fct> <dbl> <dbl>
1 2020204 0.999 6.00 tg2 2.18 1
2 2020206 0.999 2.00 tg2 -5.43 1
3 2030401 0.999 4 tg2 -5.43 1
4 2050802 4 6.00 tg2 -1.71 1
5 3040614 2.00 19.0 cens -0.791 1
6 3050925 2.00 19.0 cens 16.9 1
7 3061126 0.999 19.0 cens -1.74 1
8 3061131 4 19.0 cens -3.78 1
9 3061227 0.999 19.0 cens -0.153 1
10 3061332 2.00 19.0 cens 13.5 1
tg0
throughtg5
, or can there be a movement in the anti-gentrification direction (e.g., fromtg2
back totg1
)? $\endgroup$RAUMID
. I can't tell if that's an issue with the wrangling itself or the way the data are displayed. If you use standard multi-state survival modeling, you need at least 1 row per time epoch within eachtg
state for eachRAUMID
. If you use discrete-time survival analysis, you need 1 row per year (if that's your time scale) perRAUMID
. Be careful not to throw away useful data. $\endgroup$RAUMID
— in my dataframe I have one row for each area for each epoch for each gentrification state, with the final one either beingtg5
orcens
. Not sure why it didn't group byRAUMID
here — it does so when I click the column while inview(dataL)
$\endgroup$