pub struct DiffInDiff;Implementations§
Source§impl DiffInDiff
impl DiffInDiff
Sourcepub fn from_formula(
formula: &Formula,
data: &DataFrame,
treated_var: &str,
post_var: &str,
cov_type: CovarianceType,
) -> Result<DidResult, GreenersError>
pub fn from_formula( formula: &Formula, data: &DataFrame, treated_var: &str, post_var: &str, cov_type: CovarianceType, ) -> Result<DidResult, GreenersError>
Estimates DiD model using a formula and DataFrame.
The formula should specify the outcome variable and include ‘treated’ and ‘post’ variables. The interaction term is created automatically.
§Examples
use greeners::{DiffInDiff, DataFrame, Formula, CovarianceType};
use ndarray::Array1;
use std::collections::HashMap;
let mut data = HashMap::new();
data.insert("y".to_string(), Array1::from(vec![1.0, 2.0, 3.0, 4.0]));
data.insert("treated".to_string(), Array1::from(vec![0.0, 0.0, 1.0, 1.0]));
data.insert("post".to_string(), Array1::from(vec![0.0, 1.0, 0.0, 1.0]));
let df = DataFrame::new(data).unwrap();
let formula = Formula::parse("y ~ treated + post").unwrap();
let result = DiffInDiff::from_formula(&formula, &df, "treated", "post", CovarianceType::HC1).unwrap();Sourcepub fn fit(
y: &Array1<f64>,
treated: &Array1<f64>,
post: &Array1<f64>,
cov_type: CovarianceType,
) -> Result<DidResult, GreenersError>
pub fn fit( y: &Array1<f64>, treated: &Array1<f64>, post: &Array1<f64>, cov_type: CovarianceType, ) -> Result<DidResult, GreenersError>
Estimates the Canonical 2x2 DiD model.
§Arguments
y- Outcome variable.treated- Dummy: 1 if belongs to treatment group, 0 otherwise.post- Dummy: 1 if in post-intervention period, 0 otherwise.cov_type- Covariance type (Recommended: HC1 or Cluster if we had cluster ID).
Auto Trait Implementations§
impl Freeze for DiffInDiff
impl RefUnwindSafe for DiffInDiff
impl Send for DiffInDiff
impl Sync for DiffInDiff
impl Unpin for DiffInDiff
impl UnwindSafe for DiffInDiff
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.