Skip to content

Instantly share code, notes, and snippets.

View fditraglia's full-sized avatar

Francis DiTraglia fditraglia

View GitHub Profile
@fditraglia
fditraglia / BLPCsim.R
Last active December 15, 2019 21:08
Backward-looking Phillips Curve Simulation
#This script carries out a simulation study similar to that in Section 2 of ``Posterior Predictive Evidence on US Inflation...'' by Basturk et al (2012), exploring the effects of trend mis-specification on the estimate of the persistence of the inflation parameter.
#Library to implement Bai and Perron (2003)
library(strucchange)
set.seed(4513)
g <- 0.5 #Inflation persistence
N.sims <- 250 #Simulation repetitions
@fditraglia
fditraglia / inflation_survey_weight.R
Created May 17, 2013 21:31
Naive Weighted Inflation Forecast
library(Quandl)
p <- 100 * Quandl('FRED/GDPDEF', collapse = 'quarterly', start_date = '1960-01-01', end_date = '2012-01-01', type = 'ts', transformation = 'rdiff')
#Michigan Inflation Expectations aren't in Quandl yet
library(quantmod)
getSymbols("MICH",src="FRED")
#Median expected price change next 12 months, Survey of Consumers.
#Convert to ts object
MICH.start <- as.numeric(format.Date(start(MICH), '%Y'))
@fditraglia
fditraglia / Rtutorial1.R
Last active December 22, 2015 11:29
R Tutorial #1 - Transcript and Suggested Solution Code
x <- 5
x == 5
foo <- 3
bar <- 5
foo.bar <- foo + bar
foo.bar2 <- 2 * foo.bar
@fditraglia
fditraglia / tryRtranscript.R
Created September 6, 2013 16:00
TryR Transcript
#1.1 Expressions
1 + 1
"Arr, matey!"
6*7
#1.2 Logical Values
3 < 4
2 + 2 == 5
#1.3 Variables
@fditraglia
fditraglia / Rtutorial2.R
Created September 9, 2013 19:53
R Tutorial #2 - Transcript and Suggested Solution Code
survey <- read.csv("http://www.ditraglia.com/econ103/old_survey.csv")
survey <- survey[,1:6]
@fditraglia
fditraglia / Rtutorial3.R
Created September 23, 2013 15:52
R Tutorial #3 - Transcript and Suggested Solution Code
survey <- read.csv("http://www.ditraglia.com/econ103/old_survey.csv")
survey <- survey[,c("handedness", "height", "handspan")]
head(survey)
@fditraglia
fditraglia / Rtutorial4.R
Created October 7, 2013 19:40
R Tutorial #4 - Transcript and Suggested Solution Code
marbles <- c('red', 'blue', 'green')
sample(x = marbles, size = 2, replace = FALSE)
sample(x = 1:10, size = 5, replace = FALSE)
@fditraglia
fditraglia / Bernoulli_Binomial.R
Created October 16, 2013 17:22
This is the source code to accompany my example on the Bernoulli and Binomial RVs: http://www.ditraglia.com/econ103/Bernoulli_Binomial.html
#This function simulates n independent, identically distributed Bernoulli Random Variables
rbern <- function(n, p){
sims <- sample(0:1, size = n, replace = TRUE, prob = c(1-p, p))
return(sims)
}
@fditraglia
fditraglia / Rtutorial5.R
Last active December 26, 2015 02:19
R Tutorial #5 - Transcript and Suggested Solution Code
x <- seq(from = -1, to = 1, by = 0.5)
y <- x^2
plot(x, y)
x <- seq(from = -1, to = 1, by = 0.1)
y <- x^2
plot(x, y)
@fditraglia
fditraglia / HW7.R
Created October 21, 2013 19:58
R code to accompany solutions to Homework #7.
x <- seq(from = -5, to = 5, by = 0.01)
y1 <- dnorm(x)
y2 <- dt(x, df = 1)
y <- cbind(y1, y2)
matplot(x, y, lty = 1, type = 'l', ylab = 'f(x)')