Learn R Programming

valueprhr (version 0.1.0)

fit_twoway_fe: Fit Two-Way Fixed Effects Panel Model

Description

Fits a two-way fixed effects model with sector and time effects, regressing log production prices on log direct prices.

Usage

fit_twoway_fe(
  panel_data,
  robust_se = TRUE,
  cluster_type = c("group", "time", "twoway")
)

Value

A list containing:

model

The fitted plm model object

summary

Model summary

r2_within

Within R-squared

coeftest_robust

Coefficient test with robust SE (if robust_se=TRUE)

metrics

In-sample evaluation metrics

Arguments

panel_data

Data frame in panel format with columns: year, sector, log_direct, log_production.

robust_se

Logical. Compute robust standard errors. Default TRUE.

cluster_type

Character. Type of cluster for robust SE. One of "group", "time", or "twoway". Default "group".

Details

This function requires the 'plm' package. The model specification is: log_production ~ log_direct with two-way (sector and time) fixed effects.

Examples

Run this code
# \donttest{
if (requireNamespace("plm", quietly = TRUE)) {
  set.seed(123)
  panel <- data.frame(
    year = rep(2000:2009, 5),
    sector = rep(LETTERS[1:5], each = 10),
    log_direct = rnorm(50, 5, 0.5),
    log_production = rnorm(50, 5, 0.5)
  )
  panel$log_production <- panel$log_direct * 0.95 + rnorm(50, 0, 0.1)

  result <- fit_twoway_fe(panel)
  print(result$r2_within)
}
# }

Run the code above in your browser using DataLab