Skip to content

Instantly share code, notes, and snippets.

View jamesbrandecon's full-sized avatar

James Brand jamesbrandecon

View GitHub Profile
@jamesbrandecon
jamesbrandecon / BayesianIV.jl
Created December 5, 2023 04:23
A basic implementation of Bayesian (linear) instrumental variables regression with a single endogenous variable and a single IV. This is just a byproduct of me trying to learn more about Turing.jl and Bayesian estimation, but I'm hoping it's useful to someone as an example/starting point.
using Plots
using StatsPlots, Turing
using Distributions, LinearAlgebra, Random, FillArrays
Random.seed!(12334455)
# -------------------------------------------------------
# Models/functions for OLS and IV
# Only implemented with a single RHS variable -- easy
# to extend to multiple
@jamesbrandecon
jamesbrandecon / BayesianLogit.jl
Created December 4, 2023 03:02
Basic implementation of Bayesian Logit and BLP
# Basic implementation of Bayesian Logit and BLP
# In both cases, we model the observed market shares as coming from
# a logit model with measurement error.
using Plots
using StatsPlots
using DataFrames
using Turing, FillArrays
using LinearAlgebra, DynamicHMC
@jamesbrandecon
jamesbrandecon / FKRB.jl
Created November 24, 2023 20:03
A one-file implementation of Fox, Kim, Ryan, Bajari (2011)'s linear estimator for the mixed logit demand model, in the style of FRAC.jl and NPDemand.jl.
# This file contains a basic implementation of the FKRB estimator for the random coefficients logit model in Julia.
# In particular, it implements a constrained elastic net version of the estimator with aggregate data.
# -- Fox, Kim, Ryan, and Bajari (2011) https://onlinelibrary.wiley.com/doi/abs/10.3982/QE49
# Written by James Brand, 2023
# The main components of the code include:
# - The `logexpratio` function, which calculates market shares for a given parameter vector.
# - The `FKRBProblem` struct, which represents the FKRB problem and stores relevant data and results.
# - The `define_problem` function, which defines the FKRB problem based on input data and variables.