Skip to content

Instantly share code, notes, and snippets.

View kylebutts's full-sized avatar

Kyle F Butts kylebutts

View GitHub Profile
@kylebutts
kylebutts / simulate_bipartite.R
Created October 24, 2025 17:07
R version of bipartite simulation from `bipartitepandas`
## Adapated from bipartitepandas python package
#' Simulate Bipartite Labor Market Network
#'
#' Generates panel data for a bipartite network of workers and firms with
#' assortative matching, mobility, and AKM wage structure.
#'
#' @param n_workers Integer. Number of workers (default: 10000)
#' @param n_time Integer. Panel length in time periods (default: 5)
#' @param firm_size Numeric. Average firm size per period (default: 50)
@kylebutts
kylebutts / reprex.md
Created October 22, 2025 18:42
RDLocrand with `p=1` is the same as continuity-based estimator
library(tidyverse)
library(rdrobust)
library(rdlocrand)
hansen <- haven::read_dta(
  "https://github.com/kylebutts/UARK_5783/raw/refs/heads/main/Slides/04_RDD/data/hansen_dwi.dta"
)
est_rdlocrand <- rdlocrand::rdrandinf(
  Y = hansen$recidivism,
  R = hansen$bac1,
@kylebutts
kylebutts / README.md
Created October 21, 2025 18:40
Download the Census Address

Source: https://www.census.gov/geographies/reference-files/time-series/geo/addcountlisting.html

Block-level housing units count for the following dates: June 2022 and biannually for 2023 through 2025

The Address Count Listing Files are available for download from our file transfer protocol (FTP) site. The files include total housing units and total group quarters counts by census tabulation block from the tabs below. They are generated twice a year based on data from July and November and include data for all 50 States, the District of Columbia, Puerto Rico, and the Island Areas.

@kylebutts
kylebutts / triangle_info.R
Created June 24, 2025 20:54
Give three points of a triangle and get all angles and side lengths
triangle_info <- function(A, B, C) {
# Helper function to compute distance between two points
dist <- function(P, Q) sqrt((P[1] - Q[1])^2 + (P[2] - Q[2])^2)
# Side lengths
dist_AB <- dist(A, B)
dist_AC <- dist(A, C)
dist_BC <- dist(B, C)
# Law of Cosines for each angle
@kylebutts
kylebutts / installation.md
Last active June 7, 2025 15:07
Dev Build of Positron

Dev

  1. Download the files with gh repo clone posit-dev/positron in some directory
  2. npm i from the main directory to install packages
  3. npm run watch from the main directory to compile client and extensions (watch-client and watch-extensions). This will run continuously in the background, so you need a second terminal window

Running tests

The npm test-extension takes way too long as it runs all tests. The -g and -l options do not seem to work. Instead, I recommend opening the positron folder with vscode and it will prompt you to install a task running extension.

library(tidyverse)
library(spatstat)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.univar
#> spatstat.univar 3.1-1
#> Loading required package: spatstat.geom
#> spatstat.geom 3.3-5
#> Loading required package: spatstat.random
#> spatstat.random 3.3-2
@kylebutts
kylebutts / Poisson_Limit_Theorem.md
Created February 18, 2025 00:56
Simulations showing the Poisson Limit Theorem

Law of Rare Events / Poisson Limit Theorem

This famous theorem states that when you have:

  • A large number of independent trials ($n \to \infty$)
  • Each trial has a small probability of success ($p \to 0$)
  • The expected number of successes ($\lambda = np$) remains constant

$\implies$ the number of successes $X$ follows a Poisson distribution with parameter $\lambda$

@kylebutts
kylebutts / log.do
Created October 26, 2024 12:14
`pyfixest` #672
* https://github.com/py-econometrics/pyfixest/issues/672
. use "~/Downloads/census2000_5pc.dta", clear
(5% Extract from 2000 US Census (from Abadie et al., 2023))
.
. // set 1
. b1x2 ln_earnings, x1all(educ) x2all(hours)
Number of obs = 2632838
@kylebutts
kylebutts / 0.md
Created October 4, 2024 12:18
Plot multiple columns of a data frame and have a legend
library(ggplot2)
beta <- seq(-0.2, 0.2, by = 0.001)
exp_minus_1 <- exp(beta) - 1
(plot_pct_change_appxoimation <- ggplot() +
  geom_line(
 aes(x = beta, y = beta, color = "approx"),
@kylebutts
kylebutts / 0.md
Created September 16, 2024 13:46
Moving Hawaii and Alaska onto the US map
# Modified to use `sf` from this article:
# https://rud.is/b/2014/11/16/moving-the-earth-well-alaska-hawaii-with-r/
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(tigris)
#> To enable caching of data, set `options(tigris_use_cache = TRUE)`
#> in your R script or .Rprofile.
library(rmapshaper)
library(ggplot2)