{"id":29638948,"url":"https://github.com/beniaminogreen/cragg","last_synced_at":"2026-07-02T00:31:36.167Z","repository":{"id":181094898,"uuid":"325690260","full_name":"beniaminogreen/cragg","owner":"beniaminogreen","description":"Test for weak IV instruments in R.","archived":false,"fork":false,"pushed_at":"2021-08-26T14:51:48.000Z","size":1016,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-03T05:38:08.572Z","etag":null,"topics":["instrumental-variable","iv","ivreg2","r","regression","weak-instruments"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beniaminogreen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-12-31T02:02:33.000Z","updated_at":"2025-05-25T16:36:10.000Z","dependencies_parsed_at":"2023-07-14T02:39:07.856Z","dependency_job_id":null,"html_url":"https://github.com/beniaminogreen/cragg","commit_stats":null,"previous_names":["beniaminogreen/cragg"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beniaminogreen/cragg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beniaminogreen%2Fcragg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beniaminogreen%2Fcragg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beniaminogreen%2Fcragg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beniaminogreen%2Fcragg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beniaminogreen","download_url":"https://codeload.github.com/beniaminogreen/cragg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beniaminogreen%2Fcragg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35028642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-01T02:00:05.325Z","response_time":130,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["instrumental-variable","iv","ivreg2","r","regression","weak-instruments"],"created_at":"2025-07-21T20:07:47.518Z","updated_at":"2026-07-02T00:31:36.150Z","avatar_url":"https://github.com/beniaminogreen.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Cragg\n\n[![Build\nStatus](https://travis-ci.com/beniaminogreen/cragg.svg?branch=main)](https://travis-ci.com/beniaminogreen/cragg)\n![Codecov](https://img.shields.io/codecov/c/github/beniaminogreen/cragg)\n[![License: GPL\nv3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)\n![CRAN](https://www.r-pkg.org/badges/version/cragg)\n![Downloads](https://cranlogs.r-pkg.org/badges/last-month/cragg)\n\nAn R package to implement the Cragg-Donald test for weak instruments.\n\n## Overview\n\nThe Cragg-Donald (1993) test is a common way to test for weak\ninstruments in an IV regression but has never been implemented in R. The\ncragg package provides an implementation of the Cragg-Donald test in R\nand provides access to the critical values for the Cragg-Donald\nstatistic developed in Stock and Yogo (Stock 2005). These tests quantify\nthe degree to which weak instruments can undermine regression estimates\nfor models with multiple endogenous variables / treatments.\n\n### Main Features\n\n-   Calculates Cragg-Donald statistics for weak instruments.\n\n-   Recommends critical values for the Cragg-Donald Statistic based on\n    the largest allowable bias relative to regular OLS or the maximum\n    allowable size distortion of the Wald test statistic.\n\n## Installation\n\n``` r\ninstall.packages(\"cragg\")\nlibrary(cragg)\n```\n\n## Usage\n\nThe cragg package has two main functions `cragg_donald()`, and\n`stock_yogo_test()`.\n\n`cragg_donald()` implements the Cragg-Donald test for weak instruments\nin R. It can be thought of as the matrix-equivalent of the first-stage\nF-test for weak instruments, and is used to evaluate models with\nmultiple endogenous variables. This function has been tested against the\nresults from STATA’s ivreg2 package (Baum, Mark, Stillman 2002) to\nensure accuracy.\n\nThe syntax is show below:\n\n``` r\nlibrary(cragg)\n#Cragg-Donald Test\ncragg_donald(\n    ~X1+X2+X3,  #Controls\n    ~D1 + D2,           #Treatments\n    ~Z1 + Z2 + Z3,  #Instruments\n    data =example_data\n)\n#\u003e Cragg-Donald test for weak instruments:\n#\u003e \n#\u003e      Data:                        example_data \n#\u003e      Controls:                    ~X1 + X2 + X3 \n#\u003e      Treatments:                  ~D1 + D2 \n#\u003e      Instruments:                 ~Z1 + Z2 + Z3 \n#\u003e \n#\u003e      Cragg-Donald Statistic:        186.1346 \n#\u003e      Df:                                 993\n```\n\n`stock_yogo_test()` implements the Stock and Yogo test for weak\ninstruments. The test developed by Stock and Yogo (2005) is a decision\nrule meant to ensure that weak instruments do not pose a problem. Stock\nand Yogo suggest two methods to select the critical values: one based on\nmaximum allowable bias relative to normal OLS and another based on the\nmaximum size of a Wald test on all of the instruments. Both of these\ndecision rules are implemented.\n\n``` r\nstock_yogo_test(\n    ~X1+X2+X3,  #Controls\n    ~D1,            #Treatments\n    ~Z1 + Z2,   #Instruments\n    B=.1,       #Maximum Allowable Size Distortion\n    size_bias=\"size\", #Calculate critical value for size distortions\n    data =example_data\n)\n#\u003e Results of Stock and Yogo test for weak instruments:\n#\u003e \n#\u003e      Null Hypothesis:             Instruments are weak \n#\u003e      Alternative Hypothesis:      Instruments are not weak \n#\u003e \n#\u003e      Data:                        example_data \n#\u003e      Controls:                    ~X1 + X2 + X3 \n#\u003e      Treatments:                  ~D1 \n#\u003e      Instruments:                 ~Z1 + Z2 \n#\u003e \n#\u003e      Alpha:                             0.05 \n#\u003e      Acceptable level of bias:    10% Wald test distortion.\n#\u003e      Critical Value:                   19.93 \n#\u003e \n#\u003e      Cragg-Donald Statistic:        360.5978 \n#\u003e      Df:                                 994\n```\n\n# References\n\n\u003cdiv id=\"refs\" class=\"references csl-bib-body hanging-indent\"\u003e\n\n\u003cdiv id=\"ref-ivreg2\" class=\"csl-entry\"\u003e\n\nBaum, Christopher F, Mark E Schaffer, and Steven Stillman. 2002. “\u003cspan\nclass=\"nocase\"\u003eIVREG2: Stata module for extended instrumental\nvariables/2SLS and GMM estimation\u003c/span\u003e.” Statistical Software\nComponents, Boston College Department of Economics.\n\n\u003c/div\u003e\n\n\u003cdiv id=\"ref-Cragg_1993\" class=\"csl-entry\"\u003e\n\nCragg, John G., and Stephen G. Donald. 1993. “Testing Identifiability\nand Specification in Instrumental Variable Models.” *Econometric Theory*\n9 (2): 222–40. \u003chttps://doi.org/10.1017/s0266466600007519\u003e.\n\n\u003c/div\u003e\n\n\u003cdiv id=\"ref-Stock_2005\" class=\"csl-entry\"\u003e\n\nStock, James H., and Motohiro Yogo. 2005. “Testing for Weak Instruments\nin Linear IV Regression.” In *Identification and Inference for\nEconometric Models*, 80–108. Cambridge University Press.\n\u003chttps://doi.org/10.1017/cbo9780511614491.006\u003e.\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeniaminogreen%2Fcragg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeniaminogreen%2Fcragg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeniaminogreen%2Fcragg/lists"}