Pattern matching in Stata: chasing the devil in the details
Mael Astruc-Le Souder
UK Stata Conference 2024 from Stata Users Group
Abstract:
The vast majority of quantitative statistics now have to be estimated through computer calculations. A computation script strengthens the reproducibility of these studies but requires carefulness from the researchers when writing their code to avoid various mistakes. This presentation introduces a command implementing some checks foreign to a dynamically typed language such as Stata in the context of data analysis. This command uses a new syntax, similar to switch or match expressions, to create a variable based on other variables in place of chains of 'replace' statements with 'if' conditions. More than the syntax, the real interest of this command lies in the two properties it checks for. The first one is exhaustiveness: do the stated conditions cover all the possible cases? The second one is usefulness: are all the conditions useful, or is there redundancy between branches? I borrow the present idea of pattern matching from the Rust programming language and the earlier implementation in the OCaml programming language of the algorithm detailed in Maranget (2017) [1]. The command and source code are available on GitHub [2]. [1] MARANGET L. Warnings for Pattern Matching Journal of Functional Programming. 2007;17(3):387–421. doi:10.1017/S0956796807006223 [2] https://github.com/MaelAstruc/stata_match
Date: 2024-09-16
References: Add references at CitEc
Citations:
Downloads: (external link)
http://repec.org/lsug2024/UK24_Mael.pdf
Related works:
This item may be available elsewhere in EconPapers: Search for items with the same title.
Export reference: BibTeX
RIS (EndNote, ProCite, RefMan)
HTML/Text
Persistent link: https://EconPapers.repec.org/RePEc:boc:lsug24:23
Access Statistics for this paper
More papers in UK Stata Conference 2024 from Stata Users Group Contact information at EDIRC.
Bibliographic data for series maintained by Christopher F Baum ().