Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guides R econometrics code for panel data, difference-in-differences, instrumental variables, spatial models and publication-ready tables.
70% 96%+26 ptsof test cases passed
Passed 22 of 23 test cases with the skill, and 16 of 23 without it.
When training random forests or non-parametric ML models for causal inference in R, what command should always be run beforehand to guarantee exact numerical reproducibility?
Executes set.seed() before model training.
3 of 3 safety checks passed
library(data.table) # Data manipulation
library(fixest) # Fixed effects estimation
library(modelsummary) # Regression tables
library(ggplot2) # Visualization
library(sf) # Spatial data
library(here) # Project paths
# Read and assign
dt <- fread(here("data", "raw", "file.csv"))
# Common operations
dt[, new_var := old_var * 100] # Create variable
dt[, mean_y := mean(y, na.rm = TRUE), by = group] # Group operations
dt[year >= 2000 & treated == 1] # Filter
dt[, .(mean_y = mean(y), n = .N), by = group] # Summarize
dt[other_dt, on = .(id, year)] # Merge
# Lag/lead within groups
setorder(dt, id, year)
dt[, lag_y := shift(y, 1), by = id]
dt[, lead_y := shift(y, -1), by = id]
# Two-way fixed effects
est1 <- feols(y ~ treatment + controls | id + year, data = dt)
# Clustered standard errors (default: fixed effect groups)
est2 <- feols(y ~ treatment | id + year, data = dt, cluster = ~state)
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.