{"id":26692687,"url":"https://github.com/apoorvalal/misc_stata_ados","last_synced_at":"2026-02-04T11:44:33.862Z","repository":{"id":108043827,"uuid":"76898994","full_name":"apoorvalal/misc_stata_ados","owner":"apoorvalal","description":"Misc Utility programs in Stata. ","archived":false,"fork":false,"pushed_at":"2019-08-08T21:14:57.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T11:21:55.336Z","etag":null,"topics":["data-analysis","stata","stata-command"],"latest_commit_sha":null,"homepage":"","language":"Stata","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apoorvalal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2016-12-19T21:33:01.000Z","updated_at":"2019-08-08T21:14:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"89f062d9-bde6-44ba-ae70-c31f69c72c02","html_url":"https://github.com/apoorvalal/misc_stata_ados","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/apoorvalal/misc_stata_ados","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apoorvalal%2Fmisc_stata_ados","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apoorvalal%2Fmisc_stata_ados/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apoorvalal%2Fmisc_stata_ados/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apoorvalal%2Fmisc_stata_ados/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apoorvalal","download_url":"https://codeload.github.com/apoorvalal/misc_stata_ados/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apoorvalal%2Fmisc_stata_ados/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29083234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-04T03:31:03.593Z","status":"ssl_error","status_checked_at":"2026-02-04T03:29:50.742Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["data-analysis","stata","stata-command"],"created_at":"2025-03-26T17:34:38.534Z","updated_at":"2026-02-04T11:44:33.856Z","avatar_url":"https://github.com/apoorvalal.png","language":"Stata","funding_links":[],"categories":[],"sub_categories":[],"readme":"# misc_stata_ados\nMisc Utility programs in Stata. Brief intros below.\n\n### discretize\nCreates discrete values (bins) for a specified continuous variable, either using the percentile cutpoints specified in `cutpoints(a, b, c)` or into N number of uniform sized bins as specified in `nbins(n)`.\nUseful when trying to frame a regression specification as a classification problem to be handled using an ordered/multinomial logit (e.g. low / medium / high cost based on cutpoints).\n\n```stata\ndiscretize total_cost, gen(cost_level) cut(25 50 75)\ndiscretize total_cost, gen(bins) nbins(200)\n```\n\n### winsorize\nWinsorizes specified variable at cutpoints specified in `AT(lowerbound upperbound)` or `lim(limit 100-limit)` and optionally generates new variable.\n\n```stata\nwinsorize price, gen(newprice) at (1 99)\n```\n### freq_table\nReplaces dataset in memory with a frequency table of variables and interactions. Accepts dummy variables, factor variables, and their interactions and produces a labelled table (by extracting appropriate variable and value labels, if they exist) of counts for dummies (e.g. `female, rur_urb` ), each level of factor variables (`i.education, i.country`) and each cell in the crosstab between categorical variables separated by * or # (`i.education#i.country`).\n\nExample of use:\n```stata\n  use exampledata, clear // contains individual level data on income, sex, education, country, rural/urban location\n  gl rhs_vars female rur_urb i.educ i.country i.education#i.country\n  preserve\n  freq_table $rhs_vars\n  save freqs, replace\n  restore\n```\nfreqs.dta now contains:\n\n| Raw                       | Label                                         | Count | Pct  |\n|---------------------------|-----------------------------------------------|-------|------|\n| rur_urb == 1              | Urban == 1                                    | 24    | 0.2  |\n| educ == 1                 | Education == No HS                            | 43    | 0.36 |\n| educ == 2                 | Education == HS                               | 40    | 0.33 |\n| educ == 3                 | Education == College                          | 24    | 0.2  |\n| educ == 1 X country == 2  | Education == No HS X Country == United States | 12    | 0.1  |\n\nand so on.\n\n### dot_product\n\nCalculates the variable `Y = XB` where X is a subset of N variables in the currently loaded dataset, B is an arbitrary column vector (NX1 matrix). Basically a way to construct predicted values from a regression when the coefficients have been stored in a matrix / read in from elsewhere. Produces identical results to `predict` when used with the postestimation `e(b)` coefficient vector.\n\n```stata\nsysuse auto, clear\nmat A = [1\\2\\3]\ndot_product fitted_val A price weight trunk\n```\n\n### prefix_labels\nAdds prefix of variable label / variable name to stata value labels so that regression output can be filtered and sorted in excel. So, value labels for values `1 \"United States\" 2 \"Nepal\" 3 \"United Kingdom\"` become ` 1 \"Country: United States\" 2 \"Country: Nepal\" 3 \"Country: United Kingdom\" ` , so that excel's filter and sort functions work nicely.\n\n```stata\n  use exampledata, clear // contains individual level data on income, sex, education, country, rural/urban location\n  prefix_labels sex country education\n  reg income sex education\n  esttab using \"output.csv\", label replace\n```\n### bettertab\nWrapper for default tab/tab2 commands that temporarily adds numeric value prefixes and drops them afterwards (so that they don't affect graphs etc.)\n```stata\nbettertab race sex\n```\nreturns\n\n| Race                      | 1.F                         | 2.M              | Total    |\n|---------------------------|-----------------------------|------------------|----------|\n| 1. Black                  | 1                           | 2                |3|\n| 2. White                  | 4                           | 5                |9|\n| 3. Asian                  | 7                           | 8                |15|\n| 4. Native American        | 10                          | 11               |21|\n\n### count_unique\nDuplicate functionality with codebook, but returns scalar that can be used for calculations / stored as a variable in a loop.\n```stata\ncount_unique teacher classroom\nsca ntc = `r(nv)'\n```\n### duprep\nDetailed report on duplicates / missing values in variable.\n\n```\nduprep student_id\n// returns\n/*\n*______student_id___________*\nDistinct populated obs : 542\n% Singletons : 45\nMin obs : 1\nMean obs : 4\nMax obs: 50\n% of obs with missing values: 1\n*/\n\n```\n\n### dtimer\nA display-friendly wrapper of the default timer that displays runtime of any section of code between `dtimer on` and `dtimer off` in hours/minutes/seconds.\n\n\n### lookin\nSearches for string specified in `for()` in `varlist`, optionally generates flag for observations where matches were found.\n```\nlookin enr2000 enr2001 enr2002, for(\"Y\") g(enr_2000_2002)\n```\n### unstable\nChecks for variation in variable(s) across other variable(s)\n```\nunstable gender age, by(student)\n```\n### partition_var\nTakes `variable` and `cutpoints` and generates dummies with prefix specified in `prefix`. Example:\n```stata\npartition_var age, cut(0 35 50 75) prefix(age)\n```\ngenerates the variables (with the appropriate variable labels):\na_0_35\na_36_50\na_51_75\na76\n\n### pathmake\nGenerates entire folder structure for `path` necessary, which the native `mkdir` command cannot do.\n```\npathmake \"C:/Users/alal/Desktop/test1/temp/test2/test3/test4/test5\"\n```\ncreates the entire folder structure, even though the subdirectories didn't exist to begin with.\n\n### cond_stitcher\nReturns a long string separated by OR (|) or AND(\u0026) operators that can be used in subsequent calculations.\n\n```stata\nloc test \"age05 age610 age1115 male old\"\ncond_stitcher `test', sep(|)\n// returns \"age05|age610|age1115|male|old\"\ncount if `r(cond)'\n\u003e 55\n```\n\n### ds2\nWrapper for ds command that does not abbreviate variable names. Preferable to ds for interactive use.\n\n### okeep\nOrder and Keep varlist.\n\n\n# Installation\nRun the following line in the Stata console:\n\n`net install lal_utilities, from(https://raw.github.com/apoorvalal/misc_stata_ados/master/)`\n\nOr, if you prefer, download ados and move to your personal ado folder / `c(sysdir_personal)` (where ssc-installed ados live)\nWill upload sthlp files at some point.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapoorvalal%2Fmisc_stata_ados","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapoorvalal%2Fmisc_stata_ados","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapoorvalal%2Fmisc_stata_ados/lists"}