Scripts to use scopus API to download economics journals and articles metadata + use of Elsevier API for full-text
README.md

Building a Scopus economics database #

R scripts that build a local research database of economics journal articles from Elsevier's APIs, stored in a single DuckDB file, scopus.duckdb. They:

  1. list the economics journals indexed in Scopus,
  2. collect the metadata of their articles from the Scopus Search API,
  3. download the full-text XML of the articles published in Elsevier journals,
  4. extract paragraph-level text from these XML files,
  5. download the full Scopus record of each article, for its references, authors, affiliations and abstract.

Every step is incremental and logged in the database: running a script again only queries or processes what is missing, and an interrupted run resumes where it stopped.

A statistical description of the database is in documentation/exploring_scopus_database.qmd.

Setup #

  • Open elsevier_database.Rproj in RStudio, or otherwise run from the project root. Every script calls source("scripts/paths_and_packages.R") with a relative path.
  • scripts/paths_and_packages.R installs and loads packages with pacman::p_load(). It sets the paths and the API key for each user, based on Sys.info()[["user"]]. To run the project on a new machine, add a branch for your user there, with the same variable names.
Variable Content
data_path Main data folder: the API key file, abstract_full_json/, logs/, and old_data/ (files of the previous pipeline, including its journal lists and per-journal text RDS)
db_path The database, <data_path>/scopus.duckdb
xml_data_path Elsevier full-text XML files, one gzipped file per article (SCOPUS_ID_<id>.xml.gz, about 12 times smaller than the raw XML; xml2::read_xml() reads them directly)
econlit_data_path, wos_data_path External EconLit and Web of Science data (read-only)
api_key Elsevier API key, read from the ELSEVIER_API_KEY environment variable (~/.Renviron)

Network and quotas #

The full-text XML (step 3) and the full Scopus records (step 5) are only served to the institutional network: run these scripts on the university network or VPN. downloading_xml.R checks access before downloading and stops otherwise; all API scripts stop on HTTP 401/403 (not authorised; a commercial VPN such as Proton gets a Cloudflare 403 page) and 429 (quota reached, with the reset date).

API Used by Weekly quota (our key)
Serial Title collecting_scopus_econ_journals.R 20,000
Scopus Search collecting_scopus_metadata.R 100,000 (raised by Elsevier in October 2026; default 20,000)
Article Retrieval (full text) downloading_xml.R no quota
Abstract Retrieval collecting_scopus_references.R 100,000 (raised by Elsevier in October 2026; default 10,000)

Each API response carries the quota of the key in its headers (x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset).

Pipeline #

Serial Title API ─────► 1. collecting_scopus_econ_journals.R ──► journal
                                     │
Scopus Search API ────► 2. collecting_scopus_metadata.R ───────► article, link, metadata_query
                                     │
Article Retrieval API ► 3. downloading_xml.R ──────────────────► XML files, xml_download
                                     │
                        4. formating_text_from_xml.R ──────────► text, article_jel, article.elsevier_full_text
                                     │
Abstract Retrieval API► 5. collecting_scopus_references.R ─────► FULL records (JSON), reference, abstract_query
                                     │
                        6. parsing_scopus_full_records.R ──────► author, author_affiliation, affiliation,
                                                                  funding, correspondence, indexed_term,
                                                                  article_subject_area, article.abstract,
                                                                  article.author_keywords, article.language,
                                                                  article.funding_text
                        7. sanity_check.R ─────────────────────► (read-only checks)

1. collecting_scopus_econ_journals.R #

Pages through the Serial Title API for the Scopus subject area ECON and keeps the economics journals: ASJC codes 2000–2002 (Economics, Econometrics, General Economics) or "economic" in the title. Journals classified only under Finance (2003) are left out. It then sets three flags:

  • in_econlit: the journal is indexed in EconLit (match on ISSN, then on normalised title, against <econlit_data_path>/df_metadata.feather);
  • is_elsevier: the publisher is Elsevier or one of its imprints (Academic Press, North-Holland, Pergamon, JAI, Cell Press);
  • to_keep: Scopus coverage starts in 2005 or earlier, or the journal is in EconLit. Only to_keep journals are queried in the following steps.

The journal table is overwritten at each run; the script reports the journals added or dropped since the previous run.

2. collecting_scopus_metadata.R #

For each to_keep journal, queries the Scopus Search API (STANDARD view) year by year with SRCID(<source_id>) AND PUBYEAR IS <year>, 200 results per page. Pages are requested with the API's cursor (cursor=*, then cursor/@next): paging with start, used until October 2026, stops at 5,000 results, and the journal-years above that limit were logged truncated. The journal-years already collected are logged in metadata_query; a run only queries the years not logged as complete, plus the current and previous years (issues still being published). A year where a page fails is logged failed, its articles are not kept, and it is queried again next time; a year whose pages end before the announced number of results is kept but logged incomplete, and queried again. New articles (not yet in article) and their links are appended journal by journal, in one transaction with the log.

Set dry_run <- TRUE to print the journal-years to query without calling the API, and journal_limit to test on a few journals.

3. downloading_xml.R #

Downloads the full-text XML of the documents hosted on ScienceDirect, the only ones the Elsevier API serves, and logs each download in xml_download. A document is selected when its journal is to_keep, its Scopus type is Article, Review, Conference Paper or Book Chapter (doc_types), and:

  • its journal is flagged is_elsevier, or
  • Scopus gives the article a full-text link (link.link_type = 'full-text'), which points to the ScienceDirect API.

The second case matters because Scopus names the current publisher of a journal. About 7,000 articles of ~90 journals listed under another publisher are hosted on ScienceDirect:

  • society or university journals published by Elsevier on their behalf (Borsa Istanbul Review, Estudios Gerenciales, Review of Development Finance, Spanish Review of Financial Economics…): full run available;
  • journals that left Elsevier (Agricultural Economics, Review of Financial Economics, Journal of Forest Economics, Australasian Marketing Journal…): only their Elsevier years are on ScienceDirect, under the same subscription rules as Elsevier journals;
  • volumes of book series first published by JAI (an Elsevier imprint) and taken over by Emerald around 2008 (Research in Labor Economics, Advances in… series): Scopus still gives a full-text link, but the API answers 404 (not_found), whatever the identifier. These texts are only on Emerald Insight.

Full texts of other publishers (Wiley, Taylor & Francis, Springer, SAGE, Emerald, university presses) cannot be obtained through the Elsevier API; each publisher has its own text-mining access conditions.

Outcomes:

outcome Meaning Downloaded again?
full_text xocs:item-weight is FULL-TEXT no
no_access the API answers with metadata only, or head and references (HEAD-AND-TAIL…): no entitlement. In practice, Elsevier articles published before 1998 (backfiles not subscribed) only with retry_no_access <- TRUE
not_found HTTP 404 or another client error no
transient_error network error, timeout, HTTP 5xx yes, next run
corrupt truncated or empty file yes, next run

At its first run, the script logged the ~204,000 XML files already on disk (see classify_xml_file()), so nothing already downloaded is requested again. Each response is checked in memory (a truncated response is a transient_error and is not saved), written gzipped to a .tmp file and renamed when complete; the log is written every 500 downloads.

4. formating_text_from_xml.R #

Extracts the text of the files logged full_text that are not processed yet (xml_download.n_paragraphs is NULL) or were processed by an earlier version of the extraction (xml_download.extraction_version below text_extraction_version, set in functions.R), by chunks of 2,000 files:

  • extract_elsevier_fulltext() reads the paragraphs (ce:para), footnotes (ce:note-para) and bibliography entries (ce:bib-reference), without inline footnotes and superscript cross-references, and places each in its nearest titled block (section, acknowledgments, declaration of interest, bibliography, abstract...), with the depth, number and path of the section. It also reads the JEL codes (keyword groups of class jel);
  • clean_fulltext_paragraphs() classifies each row (type_text, see the text table); clean_jel_codes() normalises the JEL codes.

Each chunk replaces the rows of its articles in text and article_jel in one transaction, with the number of rows per file in xml_download.n_paragraphs (0 when a FULL-TEXT file has no paragraph, e.g. a scanned article, so it is not processed again) and the version in xml_download.extraction_version. At the end, article.elsevier_full_text is recomputed from text.

Extraction versions: 1 (until October 2026) carried the last section title down to the following paragraphs and dropped the reference lists; 2 adds the section hierarchy, the bibliography and the JEL codes. Bumping the version re-extracts every file from the XML on disk (about 2–3 hours).

5. collecting_scopus_references.R #

Downloads the FULL record of each article of the to_keep journals from the Abstract Retrieval API, oldest articles first (article_order), up to request_budget requests per run (one request per article; 100,000 per week on our key, so a run of 99,000 requests takes about 30–40 hours). One FULL record holds the complete reference list, the abstract, the author keywords, and the authors with their affiliations. The raw JSON is kept gzipped in <data_path>/abstract_full_json/ (3–25 KB per article), so that it can be parsed again without new requests.

The script parses the reference list into reference (one row per reference, each with the Scopus ID of the cited document) and logs each request in abstract_query (ok, not_found, transient_error).

6. parsing_scopus_full_records.R #

Parses the FULL records already downloaded (no API request) into author, author_affiliation, affiliation, funding, correspondence, indexed_term and article_subject_area, and fills article.abstract, article.author_keywords, article.language and article.funding_text. abstract_query.n_authors records the records already parsed, and abstract_query.parse_version the version of the parsing (full_record_parse_version in functions.R: 1 for authors and abstracts, 2 since October 2026 for the other fields); bumping it parses every record again from the JSON on disk.

7. sanity_check.R #

Read-only consistency checks (keys, links between tables, logs, versions, files on disk, leftover snapshot), each reported OK or WARN. It also saves the row count of each table in <data_path>/logs/sanity_check_counts.csv and warns when a table has fewer rows than at the previous run. Run it after each step.

Reading the database while a script writes: the snapshot #

While a script writes to scopus.duckdb, no other process can open it, even read-only, and the API scripts run for hours. Each writing script therefore keeps a copy, <data_path>/scopus_snapshot.duckdb: made at its start, refreshed every hour (after a CHECKPOINT, so that the file is complete), and removed at its end, when the database is free again.

The copy is a btrfs reflink (cp --reflink=always): it shares its disk blocks with the database, so it costs no disk space when it is made, and grows only as the database is rewritten (at most the size of the database, ~17 GB, during a long rewrite such as a re-extraction of the text). On a file system without reflinks, no snapshot is made (rather than doubling the disk space); refresh_snapshot(con, allow_full_copy = TRUE) forces a full copy. options(scopus.snapshot = FALSE) disables snapshots.

To read the database, use connect_read_only() (in functions.R): it opens scopus.duckdb read-only, or the snapshot when a script holds the lock, with a message giving its age. A run stopped by an error leaves its snapshot behind: the sanity check warns about it, and remove_snapshot() deletes it.

Other scripts #

  • scripts/functions.R holds the shared helpers: API calls (fetch_serial_page(), politecollect::scopus_get_page(), fetch_and_save_fulltext(), fetch_abstract_full()), XML classification and parsing (classify_xml_file(), extract_elsevier_fulltext(), bibliography_text(), clean_fulltext_paragraphs(), clean_jel_codes()), FULL-record parsing (parse_scopus_references(), parse_scopus_authors(), parse_scopus_abstract(), parse_scopus_extra()), the snapshot (refresh_snapshot(), remove_snapshot(), connect_read_only()), and title normalisation and record matching (normalize_title(), perform_record_matching(), find_duplicated_text()).
  • scripts/one_time_use/ holds migrations run once: migrate_singular_tables.R (singular table names), link_article_to_journal.R (adds article.source_id, drops the incomplete STANDARD-view affiliations after a backup in old_data/affiliation_standard_view.parquet, removes duplicates and the out-of-scope Journal of Financial Research, seeds metadata_query), compress_xml_files.R (gzips the XML files and updates file_name), and the older save_*_in_duckdb.R (move from RDS files to DuckDB).
  • scripts/depreciated/ holds earlier workflows, kept for reference: ISTEX full texts, matching Scopus with Web of Science and EconLit, RDS/parquet storage. The id_wos_matched and id_econlit_matched columns of article come from these matching scripts.

The database: scopus.duckdb #

All tables are linked through scopus_id (format SCOPUS_ID:<digits>), and articles to journals through source_id (Scopus journal ID). text is also a DuckDB type name: quote it in SQL, SELECT * FROM "text".

source("scripts/paths_and_packages.R")
source("scripts/functions.R")
con <- connect_read_only() # the database, or its snapshot while a script writes
dplyr::tbl(con, "article")

A DuckDB file can only be opened by one process when a script writes to it: close other sessions before running a script. While a script writes, connect_read_only() opens the snapshot (see above).

Row counts below are a snapshot from 3 October 2026.

Table Rows Content
journal 1,605 economics journals in Scopus
article 964,267 articles of the 1,264 to_keep journals
link 4,123,994 API hyperlinks of the articles
metadata_query 65,191 journal-years queried
xml_download ~204,000 (growing) full-text XML downloads
text 14,299,595 paragraphs of 169,430 articles
reference, abstract_query — not collected yet
author, author_affiliation, affiliation — not collected yet

journal: one row per journal #

Column Description
source_id Scopus journal ID, primary key
dc_title, dc_publisher Title and publisher
issn, e_issn Print and electronic ISSN without dash (same format as article.prism_issn)
prism_issn, prism_e_issn ISSNs as returned by the API (with dash)
coverage_start_year, coverage_end_year Years covered by Scopus (for a renamed journal, the coverage of the current title)
to_keep, in_econlit, is_elsevier Flags, see step 1
subject_codes, subject_names ASJC codes and names, separated by ";"
normalized_title Title normalised for matching
openaccess, openaccess_article, open_archive_article, openaccess_start_date Open-access information from the API
prism_url, extraction_date API URL and date of collection

article: one row per article #

The columns come from the Scopus Search API (STANDARD view), with names cleaned by janitor::clean_names(). Most are stored as VARCHAR.

Column Description
scopus_id Scopus identifier (SCOPUS_ID:…), primary key
source_id Scopus journal ID, key of journal
eid Scopus electronic ID (2-s2.0-…)
prism_url Scopus Abstract API URL of the record
dc_title Title
dc_creator First author (e.g. Howe H.)
prism_publication_name Journal name as written in the record
prism_issn Print ISSN, without dash
prism_volume, prism_issue_identifier, prism_page_range, article_number Bibliographic location
prism_cover_date Publication date (YYYY-MM-DD); the year is its first 4 characters
prism_cover_display_date Date as printed (e.g. July 1975)
prism_doi, pii DOI and Elsevier Publisher Item Identifier
citedby_count Scopus citation count at extraction date
prism_aggregation_type Journal, Book Series, Trade Journal…
subtype_description Document type: Article, Review, Editorial, Note, Conference Paper, Erratum…
extraction_date Date the record was collected (DATE)
file_name Name of the XML file: SCOPUS_ID_<id>.xml.gz
elsevier_full_text TRUE if the article has paragraphs in text
abstract, author_keywords From the FULL record (step 6); keywords separated by "; "
language Language of the article from the FULL record (step 6), ISO 639-2 code (eng, ger, dut, fre…); several separated by "; "
funding_text Funding statement as printed, from the FULL record (step 6); the funders are in funding
id_econlit_matched, id_wos_matched EconLit and Web of Science record IDs (deprecated matching scripts, older articles only)
file_size XML size from the previous pipeline, not updated; see xml_download.file_size

link: API hyperlinks, several rows per article #

Column Description
scopus_id Article identifier
link_type self, author-affiliation, scopus, scopus-citedby, full-text
href URL

metadata_query: one row per journal-year queried #

source_id, year, n_results (results announced by the API), n_fetched (records received; NULL before October 2026), status (complete, failed, incomplete when fewer records than announced were received; truncated beyond 5,000 results, for the years collected before the cursor was used), query_date.

xml_download: one row per XML download #

Column Description
scopus_id, file_name Article and XML file
http_status HTTP status of the last attempt (200 for files logged from disk)
item_weight Elsevier xocs:item-weight: FULL-TEXT, HEAD-AND-TAIL, HEAD-ONLY, CONTENTS-ENTRY-ONLY, NA (metadata only)
pub_type Elsevier document type: fla (full-length article), rev (review), brv (book review), sco (short communication)…
outcome See step 3
file_size Size of the uncompressed XML in bytes
n_attempts, last_attempt Number of attempts and date of the last one
n_paragraphs Rows extracted into text, bibliography entries included (NULL: not extracted yet; 0: none found)
extraction_version Version of the extraction that wrote the rows of text (see step 4)

text: one row per paragraph or bibliography entry #

Column Description
scopus_id Article identifier
paragraph_id Order of the row within the article (starts at 1)
text Paragraph text, whitespace squished; for a bibliography entry, the reference as printed, or the parts of the structured reference joined by spaces
section Title of the nearest enclosing block (section, or "Acknowledgements", "References", "Declaration of competing interest"…), or its number when it has no title ("Appendix A"); no_section for the body of an article without any titled section; NA for the other paragraphs outside any titled block (an introduction without heading, table cells, notes on the title and the authors)
section_level Depth of the section: 1 for a top-level section, 2 for a subsection…; NA outside sections (acknowledgments, bibliography…)
section_number Number of the block as printed (ce:label: "2", "2.1", "A.1"), when it has one
section_path Titles of the section and of the sections above it, from the top: "Model > Firms > Entry"
type_text Type of the paragraph, with the labels shared with the JSTOR and ISTEX databases, decided by the place of the paragraph in the XML first, then by the section titles: main_text (body, including the untitled paragraphs of the body: an introduction without heading, the whole text of a document without headings), footnote (footnotes of the body), front_matter (head of the article: notes on the title and the authors, data availability statement; acknowledgments, funding and declarations of interest, whose title stays in section), appendix (appendices, supplementary material), references (one entry of the reference list or of further reading), table_figure (cells and notes of tables, figure captions). header_footer is not needed: the XML holds no running heads or page numbers

For analyses of the article body, filter on type_text = 'main_text'. The section columns other than section, and the references rows, exist only for files extracted by version 2 (xml_download.extraction_version).

article_jel: JEL codes printed in the articles #

One row per article × JEL code, from the full-text XML (keyword groups of class jel), so only for articles with full text. scopus_id, jel_code (upper case, without spaces: E52, sometimes only one digit: H2; NA when the keyword holds no code, e.g. a mathematics classification code), raw (the keyword as printed, e.g. E 52 or C72 – Noncooperative games).

reference: one row per reference #

Column Description
citing_id Scopus ID of the citing article
position Order in the reference list
cited_id Scopus ID of the cited document (also for books and documents not indexed as Scopus sources)
cited_doi DOI of the cited document, when given
first_author, n_authors First author (indexed name) and number of authors
title, source_title, year Title (missing for most books, whose name is in source_title), journal or book, year
volume, issue, first_page, last_page Bibliographic location
raw_text The reference as printed, when Scopus has it

abstract_query: one row per FULL record request #

scopus_id, http_status, status (ok, not_found, transient_error), n_references, query_date, n_authors and parse_version (filled by step 6).

Tables parsed from the FULL records (step 6) #

Table One row per Columns
author article × author scopus_id, author_seq (author order), auid (Scopus author ID), indexed_name, surname, given_name
author_affiliation article × author × affiliation scopus_id, author_seq, auid, afid (Scopus affiliation ID, NA if not matched), organization (as printed, e.g. department; university), city, country
affiliation Scopus affiliation ID afid, name, city, country (normalised Scopus profile)
funding article × funder scopus_id, funding_seq, matched_string (the funder as found in the article), agency, agency_acronym, agency_id (URI in Elsevier's funder registry, SciVal Funders, whose numbers are those of the Crossref Funder Registry), agency_country (GeoNames URI), grant_id (grant numbers, separated by "; "); the agency columns are NA when Elsevier did not match the funder
correspondence article × corresponding author scopus_id, corresp_seq, author_seq and auid (matched to author on the indexed name; NA if not matched), indexed_name, surname, given_name, email (recent records only), organization, city, country (as printed)
indexed_term article × term scopus_id, term, weight, candidate: controlled terms indexed by Scopus, rare in economics (journals also indexed in Compendex, GEOBASE…)
article_subject_area article × ASJC area scopus_id, code, abbrev, name. Scopus assigns subject areas to sources, so they mostly repeat journal.subject_codes

Elsevier added the funding data to records of every age in 2021, but funders are rarely acknowledged before the 2000s.