Skip to content

Commit

Permalink
Merge pull request #114 from tidy-finance/113-update-ccmxpf_linktable…
Browse files Browse the repository at this point in the history
…-to-ccmxpf_lnkhist

Update `ccmxpf_linktable` to `ccmxpf_lnkhist` in `download_data_wrds_ccm_links()`
  • Loading branch information
christophscheuch authored Oct 12, 2024
2 parents 25a8524 + 5b43855 commit e0e2e4c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 43 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Type: Package
Package: tidyfinance
Title: Tidy Finance Helper Functions
Version: 0.4.1.9001
Version: 0.4.1.9002
Authors@R: c(
person("Christoph", "Scheuch", , "christoph.scheuch@gmail.com", role = c("aut", "cre"),
person("Christoph", "Scheuch", , "christoph.scheuch@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0009-0004-0423-6819")),
person("Stefan", "Voigt", , "stefan.voigt@econ.ku.dk", role = "aut",
person("Stefan", "Voigt", , "stefan.voigt@econ.ku.dk", role = c("aut", "cph"),
comment = c(ORCID = "0000-0001-5619-3161")),
person("Patrick", "Weiss", , "patrickw@ru.is", role = "aut",
person("Patrick", "Weiss", , "patrickw@ru.is", role = c("aut", "cph"),
comment = c(ORCID = "0000-0002-9282-5872")),
person("Maximilian", "Mücke", role = "ctb",
comment = c(ORCID = "0009-0000-9432-9795"))
Expand Down Expand Up @@ -53,4 +53,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2.9000
RoxygenNote: 7.3.2
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# tidyfinance (development version)

## Improvements

* Updated `ccmxpf_linktable` to the new WRDS default `ccmxpf_lnkhist`.

# tidyfinance 0.4.1

## Bug fixes
Expand Down
23 changes: 11 additions & 12 deletions R/download_data_wrds_ccm_links.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#' Download CCM Links from WRDS
#'
#' This function downloads data from the WRDS CRSP/Compustat Merged (CCM) links
#' database. It allows users to specify the type of links (`linktype`), the
#' primacy of the link (`linkprim`), and whether to use flagged links
#' (`usedflag`).
#' database. It allows users to specify the type of links (`linktype`) and the
#' primacy of the link (`linkprim`).
#'
#' @param linktype A character vector indicating the type of link to download.
#' The default is `c("LU", "LC")`, where "LU" stands for "Link Up" and "LC"
#' for "Link CRSP".
#' @param linkprim A character vector indicating the primacy of the link.
#' Default is `c("P", "C")`, where "P" indicates primary and "C" indicates
#' conditional links.
#' @param usedflag An integer indicating whether to use flagged links. The
#' default is `1`, indicating that only flagged links should be used.
#'
#' @returns A data frame with the columns `permno`, `gvkey`, `linkdt`, and
#' `linkenddt`, where `linkenddt` is the end date of the link, and missing end
Expand All @@ -21,10 +18,11 @@
#' @export
#' @examples
#' \donttest{
#' ccm_links <- download_data_wrds_ccm_links(linktype = "LU", linkprim = "P", usedflag = 1)
#' ccm_links <- download_data_wrds_ccm_links(linktype = "LU", linkprim = "P")
#' }
#'
download_data_wrds_ccm_links <- function(
linktype = c("LU", "LC"), linkprim = c("P", "C"), usedflag = 1
linktype = c("LU", "LC"), linkprim = c("P", "C")
) {

rlang::check_installed(
Expand All @@ -33,12 +31,13 @@ download_data_wrds_ccm_links <- function(

con <- get_wrds_connection()

ccmxpf_linktable_db <- tbl(con, I("crsp.ccmxpf_linktable"))
ccm_linking_table_db <- tbl(con, I("crsp.ccmxpf_lnkhist"))

ccm_links <- ccmxpf_linktable_db |>
filter(linktype %in% local(linktype) &
linkprim %in% local(linkprim) &
usedflag == local(usedflag)) |>
ccm_links <- ccm_linking_table_db |>
filter(
linktype %in% c("LU", "LC") &
linkprim %in% c("P", "C")
) |>
select(permno = lpermno, gvkey, linkdt, linkenddt) |>
collect() |>
mutate(linkenddt = tidyr::replace_na(linkenddt, today()))
Expand Down
2 changes: 1 addition & 1 deletion R/global_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ utils::globalVariables(
"ret_excess_vw", "ret_measure", "top", "upper_bound",
"Anlageklasse", "Asset.Class", "symbol",
"country", "industry", "ipoyear", "sector",
"..date", "..id"
"..date", "..id", "..lower_bound", "..upper_bound"
)
)
18 changes: 12 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ This repository contains an R package that collects helper functions for develop

You can install the released version of `tidyfinance` [from CRAN](https://cran.r-project.org/package=tidyfinance) via:

``` r
```r
install.packages("tidyfinance")
```

You can install the development version of `tidyfinance` from [GitHub](https://github.com/tidy-finance/r-tidyfinance) via:

``` r
```r
# install.packages("pak")
pak::pak("tidy-finance/r-tidyfinance")
```
Expand All @@ -46,7 +46,7 @@ pak::pak("tidy-finance/r-tidyfinance")

The main functionality of the `tidyfinance` package centers around data download. You can download most of the data that we used in [Tidy Finance with R](https://www.tidy-finance.org/r/index.html) using the `download_data()` function or its children. For instance, both functions give the same result:

``` r
```r
download_data(
type = "factors_ff_3_monthly",
start_date = "2000-01-01",
Expand Down Expand Up @@ -77,7 +77,7 @@ download_data_wrds_compustat(
type = "wrds_compustat_annual",
start_date = "2000-01-01",
end_date = "2020-12-31",
acoxar, amc, aldo
additional_columns = c("acoxar", "amc", "aldo")
)
```

Expand All @@ -104,8 +104,14 @@ We also include (experimental) functions that can be used for different applicat

```r
# For portfolio sorts
assign_portfolio()
?assign_portfolio()

# For model estimation
?estimate_model()

# For beta estimation
?estimate_betas()

# For beta estimation
estimate_model()
?estimate_fama_macbeth()
```
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![Project Status: Active - The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![](https://img.shields.io/badge/devel%20version-0.4.1-blue.svg)](https://github.com/tidy-finance/r-tidyfinance)
[![](https://img.shields.io/badge/devel%20version-0.4.1.9002-blue.svg)](https://github.com/tidy-finance/r-tidyfinance)
[![R-CMD-check](https://github.com/tidy-finance/r-tidyfinance/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidy-finance/r-tidyfinance/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

Expand Down Expand Up @@ -83,7 +83,7 @@ download_data_wrds_compustat(
type = "wrds_compustat_annual",
start_date = "2000-01-01",
end_date = "2020-12-31",
acoxar, amc, aldo
additional_columns = c("acoxar", "amc", "aldo")
)
```

Expand Down Expand Up @@ -116,8 +116,14 @@ versions as we try to make them more general:

``` r
# For portfolio sorts
assign_portfolio()
?assign_portfolio()

# For model estimation
?estimate_model()

# For beta estimation
?estimate_betas()

# For beta estimation
estimate_model()
?estimate_fama_macbeth()
```
17 changes: 5 additions & 12 deletions man/download_data_wrds_ccm_links.Rd

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

6 changes: 3 additions & 3 deletions man/tidyfinance-package.Rd

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

0 comments on commit e0e2e4c

Please sign in to comment.