Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Imports:
Rcpp,
magrittr,
MASS,
stats
stats,
tidyr,
coop
LinkingTo:
Rcpp,
RcppEigen
Depends:
R (>= 3.50)
R (>= 3.5.0)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
export(staggered)
export(staggered_cs)
export(staggered_sa)
import(Rcpp)
importFrom(magrittr,"%>%")
useDynLib(staggered)
8 changes: 8 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ eigenMapMatMult <- function(A, B) {
.Call('_staggered_eigenMapMatMult', PACKAGE = 'staggered', A, B)
}

solve_least_squares_svd <- function(A, B) {
.Call('_staggered_solve_least_squares_svd', PACKAGE = 'staggered', A, B)
}

solve_least_squares_normal <- function(A, B) {
.Call('_staggered_solve_least_squares_normal', PACKAGE = 'staggered', A, B)
}

365 changes: 208 additions & 157 deletions R/compute_efficient_estimator_and_se.R

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ We also provide a Stata implementation (staggered_stata) via the RCall package,
To install the staggered_stata package, the user first needs to install the github and RCall packages. This can be done with the following commands

> net install github, from("https://haghish.github.io/github/")
> github install haghish/rcall, stable
> github install haghish/rcall, version("2.5.0")

Note that the user must have R installed before installing the rcall package. The latest version of R can be downloaded [here](https://cloud.r-project.org/). The staggered_stata package can then be installed with
**Important note:** the staggered_stata package was built under Rcall version 2.5.0, and the recent release of RCall version 3.0 has created some compatibility issues. We will try our best to fix these issues, but in the meantime it is best to install version 2.5.0, as in the command above.

Note that the user must have R installed before installing the RCall package. The latest version of R can be downloaded [here](https://cloud.r-project.org/). The staggered_stata package can then be installed with

> github install jonathandroth/staggered_stata

Expand All @@ -164,4 +166,4 @@ The syntax for staggered_stata is very similar to that for the staggered R packa

![Stata examples.](man/figures/Stata_screenshot.png)

The staggered, staggered_cs, and staggered_as commands all return a vector of coefficients and covariance matrix in ereturn list, and thus can be used with any post-estimation command in Stata (e.g. coefplot).
The staggered, staggered_cs, and staggered_as commands all return a vector of coefficients and covariance matrix in ereturn list, and thus can be used with any post-estimation command in Stata (e.g. coefplot).
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# staggered

<!-- badges: start -->

<!-- badges: end -->

The staggered R package computes the efficient estimator for settings
Expand Down Expand Up @@ -45,7 +46,7 @@ for modifying and plotting the results.
``` r
library(staggered) #load the staggered package
library(dplyr) #load dplyr for data manipulation
#> Warning: package 'dplyr' was built under R version 4.0.2
#> Warning: package 'dplyr' was built under R version 4.0.5
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
Expand All @@ -55,7 +56,7 @@ library(dplyr) #load dplyr for data manipulation
#>
#> intersect, setdiff, setequal, union
library(ggplot2) #load ggplot2 for plotting the results
#> Warning: package 'ggplot2' was built under R version 4.0.2
#> Warning: package 'ggplot2' was built under R version 4.0.5
library(purrr)

df <- staggered::pj_officer_level_balanced #load the officer data
Expand Down Expand Up @@ -204,9 +205,15 @@ the github and RCall packages. This can be done with the following
commands

> net install github, from("https://haghish.github.io/github/")
> github install haghish/rcall, stable
> github install haghish/rcall, version("2.5.0")

**Important note:** the staggered\_stata package was built under Rcall
version 2.5.0, and the recent release of RCall version 3.0 has created
some compatibility issues. We will try our best to fix these issues, but
in the meantime it is best to install version 2.5.0, as in the command
above.

Note that the user must have R installed before installing the rcall
Note that the user must have R installed before installing the RCall
package. The latest version of R can be downloaded
[here](https://cloud.r-project.org/). The staggered\_stata package can
then be installed with
Expand Down
4 changes: 3 additions & 1 deletion man/compute_g_level_summaries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/README-unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion man/staggered.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/staggered_cs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/staggered_sa.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,35 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// solve_least_squares_svd
Eigen::MatrixXd solve_least_squares_svd(Eigen::MatrixXd A, Eigen::MatrixXd B);
RcppExport SEXP _staggered_solve_least_squares_svd(SEXP ASEXP, SEXP BSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Eigen::MatrixXd >::type A(ASEXP);
Rcpp::traits::input_parameter< Eigen::MatrixXd >::type B(BSEXP);
rcpp_result_gen = Rcpp::wrap(solve_least_squares_svd(A, B));
return rcpp_result_gen;
END_RCPP
}
// solve_least_squares_normal
Eigen::MatrixXd solve_least_squares_normal(Eigen::MatrixXd A, Eigen::MatrixXd B);
RcppExport SEXP _staggered_solve_least_squares_normal(SEXP ASEXP, SEXP BSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Eigen::MatrixXd >::type A(ASEXP);
Rcpp::traits::input_parameter< Eigen::MatrixXd >::type B(BSEXP);
rcpp_result_gen = Rcpp::wrap(solve_least_squares_normal(A, B));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_staggered_eigenMapMatMult", (DL_FUNC) &_staggered_eigenMapMatMult, 2},
{"_staggered_solve_least_squares_svd", (DL_FUNC) &_staggered_solve_least_squares_svd, 2},
{"_staggered_solve_least_squares_normal", (DL_FUNC) &_staggered_solve_least_squares_normal, 2},
{NULL, NULL, 0}
};

Expand Down
21 changes: 21 additions & 0 deletions src/code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,24 @@ SEXP eigenMapMatMult(const Eigen::Map<Eigen::MatrixXd> A, Eigen::Map<Eigen::Matr

return Rcpp::wrap(C);
}


// [[Rcpp::export]]
Eigen::MatrixXd solve_least_squares_svd(
Eigen::MatrixXd A,
Eigen::MatrixXd B
) {
Eigen::MatrixXd x = A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(B);
return(x);
}


// [[Rcpp::export]]
Eigen::MatrixXd solve_least_squares_normal(
Eigen::MatrixXd A,
Eigen::MatrixXd B
) {
Eigen::MatrixXd x = (A.transpose() * A).ldlt().solve(A.transpose() * B);
return(x);
}