{"id":22144025,"url":"https://github.com/pytask-dev/pytask-stata","last_synced_at":"2025-07-26T01:31:02.334Z","repository":{"id":42010860,"uuid":"300551217","full_name":"pytask-dev/pytask-stata","owner":"pytask-dev","description":"Execute do-files with Stata and pytask.","archived":false,"fork":false,"pushed_at":"2025-07-14T17:52:05.000Z","size":99,"stargazers_count":3,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-14T22:38:35.539Z","etag":null,"topics":["pytask"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pytask-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-02T08:31:42.000Z","updated_at":"2024-05-26T21:15:25.000Z","dependencies_parsed_at":"2023-12-25T20:25:04.290Z","dependency_job_id":"98676f35-66ff-4db4-9e7b-15c8d14750d0","html_url":"https://github.com/pytask-dev/pytask-stata","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":0.2666666666666667,"last_synced_commit":"a96ff6922b6ccd59c72eec7afd8d5ca2332cf5c4"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/pytask-dev/pytask-stata","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytask-dev%2Fpytask-stata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytask-dev%2Fpytask-stata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytask-dev%2Fpytask-stata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytask-dev%2Fpytask-stata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pytask-dev","download_url":"https://codeload.github.com/pytask-dev/pytask-stata/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytask-dev%2Fpytask-stata/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267100094,"owners_count":24036102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"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":["pytask"],"created_at":"2024-12-01T22:18:08.551Z","updated_at":"2025-07-26T01:31:01.946Z","avatar_url":"https://github.com/pytask-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytask-stata\n\n[![PyPI](https://img.shields.io/pypi/v/pytask-stata?color=blue)](https://pypi.org/project/pytask-stata)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytask-stata)](https://pypi.org/project/pytask-stata)\n[![image](https://img.shields.io/conda/vn/conda-forge/pytask-stata.svg)](https://anaconda.org/conda-forge/pytask-stata)\n[![image](https://img.shields.io/conda/pn/conda-forge/pytask-stata.svg)](https://anaconda.org/conda-forge/pytask-stata)\n[![PyPI - License](https://img.shields.io/pypi/l/pytask-stata)](https://pypi.org/project/pytask-stata)\n[![image](https://img.shields.io/github/actions/workflow/status/pytask-dev/pytask-stata/main.yml?branch=main)](https://github.com/pytask-dev/pytask-stata/actions?query=branch%3Amain)\n[![image](https://codecov.io/gh/pytask-dev/pytask-stata/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/pytask-stata)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pytask-dev/pytask-stata/main.svg)](https://results.pre-commit.ci/latest/github/pytask-dev/pytask-stata/main)\n[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n______________________________________________________________________\n\nRun Stata's do-files with pytask.\n\n## Installation\n\npytask-stata is available on [PyPI](https://pypi.org/project/pytask-stata) and\n[Anaconda.org](https://anaconda.org/conda-forge/pytask-stata). Install it with\n\n```console\n$ pip install pytask-stata\n\n# or\n\n$ conda install -c conda-forge pytask-stata\n```\n\nYou also need to have Stata installed on your system and have the executable on your\nsystem's PATH. If you do not know how to do it, [here](https://superuser.com/a/284351)\nis an explanation.\n\n## Usage\n\nSimilarly to normal task functions which execute Python code, you define tasks to\nexecute scripts written in Stata with Python functions. The difference is that the\nfunction body does not contain any logic, but the decorator tells pytask how to handle\nthe task.\n\nHere is an example where you want to run `script.do`.\n\n```python\nimport pytask\n\n\n@pytask.mark.stata(script=\"script.do\")\n@pytask.mark.produces(\"auto.dta\")\ndef task_run_do_file():\n    pass\n```\n\nWhen executing a do-file, the current working directory changes to the directory where\nthe script is located. This allows you, for example, to reference every data set you\nwant to read with a relative path from the script.\n\n### Dependencies and Products\n\nDependencies and products can be added as with a normal pytask task using the\n`@pytask.mark.depends_on` and `@pytask.mark.produces` decorators. which is explained in\nthis\n[tutorial](https://pytask-dev.readthedocs.io/en/stable/tutorials/defining_dependencies_products.html).\n\n### Accessing dependencies and products in the script\n\nThe decorator can be used to pass command line arguments to your Stata executable. For\nexample, pass the path of the product with\n\n```python\n@pytask.mark.stata(script=\"script.do\", options=\"auto.dta\")\n@pytask.mark.produces(\"auto.dta\")\ndef task_run_do_file():\n    pass\n```\n\nAnd in your `script.do`, you can intercept the value with\n\n```do\n* Intercept command line argument and save to macro named 'produces'.\nargs produces\n\nsysuse auto, clear\nsave \"`produces'\"\n```\n\nThe relative path inside the do-file works only because the pytask-stata switches the\ncurrent working directory to the directory of the do-file before the task is executed.\n\nTo make the task independent from the current working directory, pass the full path as\nan command line argument. Here is an example.\n\n```python\n# Absolute path to the build directory.\nfrom src.config import BLD\n\n\n@pytask.mark.stata(script=\"script.do\", options=BLD / \"auto.dta\")\n@pytask.mark.produces(BLD / \"auto.dta\")\ndef task_run_do_file():\n    pass\n```\n\n### Repeating tasks with different scripts or inputs\n\nYou can also parametrize the execution of scripts, meaning executing multiple do-files\nas well as passing different command line arguments to the same do-file.\n\nThe following task executes two do-files which produce different outputs.\n\n```python\nfor i in range(2):\n\n    @pytask.mark.task\n    @pytask.mark.stata(script=f\"script_{i}.do\", options=f\"{i}.dta\")\n    @pytask.mark.produces(f\"{i}.dta\")\n    def task_execute_do_file():\n        pass\n```\n\n## Configuration\n\npytask-stata can be configured with the following options.\n\n*`stata_keep_log`*\n\nUse this option to keep the `.log` files which are produced for every task. This option\nis useful to debug Stata tasks. Set the option via the configuration file with\n\n```toml\n[tool.pytask.ini_options]\nstata_keep_log = true\n```\n\nThe option is also available in the command line interface via the `--stata-keep-log`\nflag.\n\n*`stata_check_log_lines`*\n\nUse this option to vary the number of lines in the log file which are checked for error\ncodes. It also controls the number of lines displayed on errors. Use any integer greater\nthan zero. Here is the entry in the configuration file\n\n```toml\n[tool.pytask.ini_options]\nstata_check_log_lines = 10\n```\n\nand here via the command line interface\n\n```console\n$ pytask build --stata-check-log-lines 10\n```\n\n## Changes\n\nConsult the [release notes](CHANGES.md) to find out about what is new.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytask-dev%2Fpytask-stata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpytask-dev%2Fpytask-stata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytask-dev%2Fpytask-stata/lists"}