library( dplyr )
library( knitr )
library( pander )
library( stargazer )
library( scales )

# set stargazer type to text for 
# previewing in RMD docs but
# convert to type HTML when knitting
# (next code chunk)

s.type <- "text"  
###################################
#
#     STARGAZER SETTINGS
#
###################################

# DO NOT RUN CHUNK UNLESS KNITTING:
# changes table formats to html
# before rendering RMD docs

s.type <- "html"

For this part of the project you will:

This tutorial demonstrates some of the initial steps of variable creation and data exploration for the project.

Data

See the data steps for the wrangling that occurs during the process of creating our rodeo datasets.

## [1] 72693
## [1] 72693

Filter Rural Districts

## 
## rural urban 
## 12971 59722

Identify Common Variables

We can create a function to compare variables from the 2000 and 2010 datasets:

## [1] "SHARED VARIABLES:"
##   [1] "a15asn"  "a15blk"  "a15hsp"  "a15ntv"  "a15wht"  "a18und"  "a60asn" 
##   [8] "a60blk"  "a60hsp"  "a60ntv"  "a60up"   "a60wht"  "a75up"   "ag15up" 
##  [15] "ag18cv"  "ag25up"  "ag5up"   "ageasn"  "ageblk"  "agehsp"  "agentv" 
##  [22] "agewht"  "asian"   "china"   "clf"     "col"     "cuban"   "dapov"  
##  [29] "dbpov"   "dflabf"  "dfmpov"  "dhpov"   "dmulti"  "dnapov"  "dpov"   
##  [36] "dwpov"   "empclf"  "family"  "fb"      "fhh"     "filip"   "flabf"  
##  [43] "geanc"   "gefb"    "h10yrs"  "h30old"  "haw"     "hh"      "hha"    
##  [50] "hhb"     "hhh"     "hhw"     "hinc"    "hinca"   "hincb"   "hinch"  
##  [57] "hincw"   "hisp"    "hs"      "hu"      "incpc"   "india"   "iranc"  
##  [64] "irfb"    "itanc"   "itfb"    "japan"   "korea"   "lep"     "manuf"  
##  [71] "mar"     "mex"     "mhmval"  "mrent"   "multi"   "n10imm"  "n65pov" 
##  [78] "napov"   "nat"     "nbpov"   "nfmpov"  "nhblk"   "nhpov"   "nhwht"  
##  [85] "nnapov"  "npov"    "ntv"     "nwpov"   "ohu"     "olang"   "own"    
##  [92] "pop"     "pr"      "prof"    "rent"    "ruanc"   "rufb"    "scanc"  
##  [99] "scfb"    "semp"    "tractid" "unemp"   "vac"     "vet"     "viet"   
## [106] "wds"    
## [1] "NOT SHARED:"
##  [1] "a65asn"  "a65blk"  "a65hsp"  "a65ntv"  "a65wht"  "cni16u"  "dis"    
##  [8] "hu00sp"  "ohu00sp" "p10imm"  "p10yrs"  "p15asn"  "p15blk"  "p15hsp" 
## [15] "p15ntv"  "p15wht"  "p18und"  "p30old"  "p60up"   "p65asn"  "p65blk" 
## [22] "p65hsp"  "p65ntv"  "p65pov"  "p65wht"  "p75up"   "papov"   "pasian" 
## [29] "pbpov"   "pchina"  "pcol"    "pcuban"  "pfb"     "pfhh"    "pfilip" 
## [36] "pflabf"  "pfmpov"  "pgeanc"  "pgefb"   "phaw"    "phisp"   "phpov"  
## [43] "phs"     "pindia"  "piranc"  "pirfb"   "pitanc"  "pitfb"   "pjapan" 
## [50] "pkorea"  "plep"    "pmanuf"  "pmar"    "pmex"    "pmulti"  "pnapov" 
## [57] "pnat"    "pnhblk"  "pnhwht"  "pntv"    "polang"  "pown"    "ppov"   
## [64] "ppr"     "pprof"   "pruanc"  "prufb"   "pscanc"  "pscfb"   "psemp"  
## [71] "punemp"  "pvac"    "pvet"    "pviet"   "pwds"    "pwpov"

Create Dataset for Analysis

Create subset for the analysis

If you call the stargazer() function with a linear model object (a regression model) it will create a nicely-formatted regression table for you.

If you instead use a data frame object it will create a table of descriptive statistics.

You can set the statistics you would like reported in the table with the summary.stat= argument.

Statistic Min Pctl(25) Median Mean Pctl(75) Max
mhmval00 0 81,600 119,900 144,738 173,894 1,000,001
mhmval12 9,999 123,200 193,200 246,570 312,000 1,000,001
hinc00 2,499 33,000 43,825 47,657 58,036 200,001
hu00 0 1,102 1,519 1,570 1,999 11,522
own00 0 542 902 939 1,289 4,911
rent00 0 195 398 516 712 8,544
empclf00 0 1,205 1,756 1,820 2,373 10,334
clf00 0 1,302 1,865 1,930 2,502 11,251
unemp00 0 51 87 110 140 6,405
prof00 0 299 539 637 873 6,610
dpov00 0 2,671 3,718 3,804 4,871 23,892
npov00 0 149 304 452 601 5,515
ag25up00 0 1,763 2,451 2,520 3,224 17,974
hs00 0 665 1,071 1,155 1,552 8,909
col00 0 243 492 665 923 9,313
pop00.x 0 2,751 3,802 3,901 4,976 36,206
nhwht00 0 1,308 2,514 2,591 3,713 20,619
nhblk00 0 41 141 522 527 14,039
hisp00 0 55 153 547 533 13,391
asian00 0 22 65 189 183 9,491
p.white 0 47 78 67 91 100
p.black 0 1 4 14 14 100
p.hisp 0 2 4 13 15 100
p.asian 0 1 2 5 5 95
p.hs 0 67 72 72 77 100
p.col 0 12 21 26 36 100
p.prof 0 23 31 34 43 100
p.unemp 0 3 5 6 8 100
pov.rate 0 4 9 12 17 100

Exploration of Median Home Value

Initial conditions in 2000:

Statistic Min Pctl(25) Median Mean Pctl(75) Max
MedianHomeValue2000 0 105,146 154,497 186,502 224,071 1,288,551
MedianHomeValue2010 9,999 123,200 193,200 246,570 312,000 1,000,001
Change.00.to.10 -1,228,651 7,187 36,268 60,047 94,881 1,000,001

A note on inflation calculations. You can google “inflation calculator” and you will find a bunch of sites that give you the conversion. Just select 2010 as the final year, your input year, and use $1 as the starting value. For example:

https://westegg.com/inflation/

You will get slightly different results by site.

Otherwise, you can always estimate it if you know the average long-term inflation rate. Since 2000 the rate has averaged about 2.5% in the US, so you can use:

Prior to 2000 the rates were higher and they fluctuated quite a bit through the 70’s and 80’s so if you are going back in time further it is better to use a calculator. The calculators should use the actual rates by year.

Histogram of MHV

Compare 2000 to 2010 distributions.

layout.matrix <- matrix( c( 1,3,
                            2,3 ), 
                nrow=2, ncol=2, byrow=T )

layout( mat = layout.matrix,
        heights = c(2,2), # Heights of the two rows
        widths =  c(3,4)) # Widths of the two columns

# layout.show(3)

par( mar=c(4,0,0,2) )

hist( mhv.00/1000, breaks=50, 
      xlim=c(-200,800), yaxt="n", xaxt="n",
      xlab="", cex.lab=1,
      ylab="", main="",
      col="darkslateblue", border="white" )

axis( side=1, at=seq( from=0, to=1000, by=100 ), 
      labels=paste0( "$", seq( from=0, to=1000, by=100 ), "k" ) )

abline( v=seq(0,1000,100), lty=2, col="gray80" )

text( 550, 4000, labels="Median Home \nValue in 2000", 
      col="darkslateblue", cex=1.8 )



hist( mhv.10/1000, breaks=50, 
      xlim=c(-200,800), yaxt="n", xaxt="n",
      xlab="", cex.lab=1,
      ylab="", main="",
      col="darkslateblue", border="white" )

abline( v=seq(0,1000, 100 ), lty=2, col="gray80" )

text( 550, 3500, labels="Median Home \nValue in 2010", 
      col="darkslateblue", cex=1.8 )

axis( side=1, at=seq( from=0, to=1000, by=100 ), 
      labels=paste0( "$", seq( from=0, to=1000, by=100 ), "k" ) )


# data reduction - filter 1,000 observations

df <- data.frame( v00=mhv.00/1000, v10=mhv.10/1000 )
df <- sample_n( df, 1000 )

par( mar=c(4,5,3,2) )

jplot( df$v00, df$v10, 
       lab1="MHV in 2000", lab2="MHV in 2010",
       xlim=c(0,1000), ylim=c(0,1000),
       axes=F )

abline( a=0, b=1, lty=2, col="gray" )
axis( side=1, at=seq( from=0, to=1000, by=200 ), 
      labels=paste0( "$", seq( from=0, to=1000, by=200 ), "k" ) )
axis( side=2, at=seq( from=0, to=1000, by=200 ), 
      labels=paste0( "$", seq( from=0, to=1000, by=200 ), "k" ) )

Change in MHV 2000-2010

If a home worth $10 million increased in value by $100k over ten years it would not be that surprising. If a home worth $50k increased by $100k over the same period that is a growth of 200% and is notable.

The change in value variable only reports absolute change, but does not provide a sense of whether that is a big or small amount for the census tract.

The percent change variable provides some context for growth rates of value in census tracts.

##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
##  -0.9689   0.0592   0.2540   0.3380   0.4956 174.9356      217
## [1] 115

Plot the percent change variable:

Group Growth Rates By Metro Area

We often want to disagregate descriptives by some grouping in the data, such as metro areas.

dplyr makes this easy by grouping then summarizing the data.

cbsaname ave.change.d growth
Ocean City, NJ $154,667 93.07
Virginia Beach-Norfolk-Newport News, VA $97,955 71.81
Casper, WY $70,770 70.03
New York-Wayne-White Plains, NY-NJ $189,118 69.86
Kingston, NY $89,272 65.08
Barnstable Town, MA $146,088 65.07
Washington-Arlington-Alexandria DC-VA $139,136 64.82
Charlottesville, VA $104,487 62.74
Atlan City, NJ $94,239 62.32
Baltimore-Towson, MD $102,918 61.9
Bethesda-Frederick-Gaithersburg, MD $146,639 61.46
San Luis Obispo-Paso Robles, CA $172,722 61.01
Midland, TX $54,576 60.3
Los Angeles-Long Beach-Santa Ana, CA $145,968 60.3
Honolulu, HI $194,665 59.21
Redding, CA $87,677 59.12
Chico, CA $81,746 57.83
Nassau-Suffolk, NY $149,785 57.62
Edison, NJ $125,056 57.19
Santa Ana-Anaheim-Irvine, CA $177,367 56.05
Poughkeepsie-Newburgh-Middletown, NY $101,010 55.18
Flagstaff, AZ $71,072 54.67
Salisbury, MD $60,400 54.06
Winchester, VA-WV $73,165 53.76
Odessa, TX $26,240 53.37

Measuring Gentrification

The original merged dataset we saved as d.full so we don’t need to reload it:

Recall our data steps thus far:

##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
##   -96.89     5.92    25.40    33.80    49.56 17493.56      217

Select Gentrification Variables

Select variables for operationalizing a definition of gentrification:

We need to add some variables from 2010:

Recall we created a 2000 to 2010 variable list for reference:

Descriptive Statistics of Change Variables

Statistic Min Pctl(25) Median Mean Pctl(75) Max
mhv.00 1,280 105,661 154,884 187,119 224,337 1,288,551
mhv.10 9,999 123,200 193,200 246,570 312,000 1,000,001
mhv.change -1,228,651 7,101 35,985 59,378 94,142 983,765
pct.change -97 6 25 34 50 17,494
p.white.00 0 47 78 67 91 100
p.black.00 0 1 4 14 14 100
p.hisp.00 0 2 4 13 15 100
p.asian.00 0 1 2 5 5 95
p.hs.edu.00 0 67 72 72 77 100
p.col.edu.00 0 12 21 26 36 100
p.prof.00 0 23 31 34 43 100
p.unemp.00 0 3 5 6 8 100
pov.rate.00 0 4 9 12 17 100
p.white.10 0 37 70 60 87 100
p.black.10 0 2 5 15 17 100
p.hisp.10 0 3 7 17 21 100
p.asian.10 0 1 3 6 6 96
p.hs.edu.10 0 66 71 71 77 100
p.col.edu.10 0 15 25 30 41 100
p.prof.10 0 24 34 35 46 100
p.unemp.10 0 6 9 10 13 100
pov.rate.10 0 6 12 16 22 100
metro.mhv.pct.00 1 25 50 50 75 100
metro.mhv.pct.10 1 25 50 50 75 100
metro.median.pay.00 23,012 39,457 43,139 45,054 49,522 73,701
metro.median.pay.10 30,337 47,736 54,728 55,905 60,119 96,033
metro.mhv.pct.change -99 -6 -1 0 5 99
pay.change -3,207 7,495 9,764 10,851 13,809 27,310
race.change -100 -10 -5 -6 -1 90
metro.race.rank.00 1 25 50 50 75 100

Operationalizing Gentrification

Which definition did you select for gentrification, and how would you operationalize it?

## [1] 1185
## [1] 20674
## [1] 0.05731837

By this definition only 5.7 percent of urban tracts experience gentrification between 2000 and 2010.

This might skew numbers?

##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
##   -96.89     5.92    25.40    33.80    49.56 17493.56      217

Discussion

What do you think? Is that the right way to operationalize it? Do you care about relative diversity (more diverse neighborhood than rest of the city) or absolute (percentage of non-whites regardless of city diversity).

Do we care about absolute increase in value, or relative to the national average? The national average would include all of the gentrifying tracts, which could skew it upward and thus make it a poor benchmark? Maybe look at the average increase in value for non-gentrification candadidates?

Spatial Visualization

Dust off your GIS skills from CPP 529 so that you can visualize some of your metrics.

You will need to pick one or more cities that you can use as examples in your report. It is strongly recommended that you create a dorling cartogram for reporting since Census tracts introduce visual bias by over-empasizing lower density tracts and hiding a lot of the data where the greatest number of people reside in the city. Recall that Dorling cartograms correct for this by re-sizing administrative units proportion to the size of the population they represent.

The lab from CPP 528 that covers creating Dorling cartograms is locate here:

https://ds4ps.org/cpp-529-master/labs/lab-04-instructions.html

## [1] "character"
## [1] "01001020100" "01001020200" "01001020300" "01001020400" "01001020500"
## [6] "01001020600"

Note the current class of the PHX shapefile IDs:

You can either convert the data frame ID to numeric to drop the leading zero and merge with GEOID2.

Or keep it as a character vector and merge with GEOID.

## [1] 913
## [1] 913