************* fetch_dta() ************* Description =========== Fetch a dataset directly from Stata Press web repository. Parameters ========== Input ----- **fetch_dta(name: str, version: Optional[str] = None, timeout: int = 30) -> pd.DataFrame** * **name**: str; Dataset filename without extension (e.g., 'auto', 'nlsw88'). * **version**: str, optional; Stata version directory (e.g., 'r19', 'r18'). Defaults to 'r19'. * **force_download**: bool, default False; If True, re-download even if available locally. * **timeout** : int, default 30; Maximum time in seconds to wait for a response from the server. .. note:: **Fetching Common Datasets** Convience wrapper functions for common datasets are provided. These functions are named after the dataset and can be called directly without needing to specify the dataset name or version. *These functions only accept the **version** parameter*. Returns ------- pandas.DataFrame * A DataFrame containing the dataset fetched from the Stata Press web repository with appropriate dtypes preserved. Raises ------ * **ValueError**: If the dataset name is not found in the specified version directory. * **requests.exceptions.RequestException**: If there is an issue with the network request (e.g., timeout, connection error). Examples ======== .. code:: python import researchpy as rp Get dataset (default latest version) ------------------------------------------ .. code:: python import researchpy as rp df = rp.datasets.stata_webuse.fetch_dta('auto') .. raw:: html
make price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
0 AMC Concord 4099 22 3.0 2.5 11 2930 186 40 121 3.58 Domestic
1 AMC Pacer 4749 17 3.0 3.0 11 3350 173 40 258 2.53 Domestic
2 AMC Spirit 3799 22 NaN 3.0 12 2640 168 35 121 3.08 Domestic
3 Buick Century 4816 20 3.0 4.5 16 3250 196 40 196 2.93 Domestic
4 Buick Electra 7827 15 4.0 4.0 20 4080 222 43 350 2.41 Domestic
'
Specify dataset version ------------------------- .. code:: python import researchpy as rp df_old = rp.datasets.stata_webuse.fetch_dta('auto',version='r15') Force refresh download from server ----------------------------------- .. code:: python import researchpy as rp df_new = rp.datasets.stata_webuse.fetch_dta('auto',force_download=True) Fetching Common Datasets ------------------------- .. code:: python import researchpy as rp auto = rp.datasets.stata_webuse.auto() nlsw88 = rp.datasets.stata_webuse.nlsw88() systolic = rp.datasets.stata_webuse.systolic() lbw = rp.datasets.stata_webuse.lbw() census = rp.datasets.stata_webuse.census() citytemp = rp.datasets.stata_webuse.citytemp() cancer = rp.datasets.stata_webuse.cancer() lifeexp = rp.datasets.stata_webuse.lifeexp() sp500 = rp.datasets.stata_webuse.sp500() uslifeexp = rp.datasets.stata_webuse.uslifeexp() voter = rp.datasets.stata_webuse.voter() References =========== .. footbibliography::