Giter VIP home page Giter VIP logo

stata_argmax's Introduction

Stata package for finding argmax and argmin

Installing

You can clone the Git repo with

git clone https://github.com/jrfiedler/stata_argmax

Or you can download a zip archive by clicking on the "Download ZIP" button on the right side of this page.

Syntax

argmax varname [if] [in] [, options]

argmin varname [if] [in] [, options]

options:

  1. by(varlist)
  • group by specified variables when finding values; the values will be calculated separately in each group implied by varlist
  1. eval(varlist)
  • evaluate specified variables at returned observation number(s)

Description

argmax/argmin finds the observation number of the max/min value of the given numeric variable varname. Missing values are excluded. If the max/min value occurs in multiple observations, then argmax/argmin finds all such observations. If the option eval(varlist) is specified, then argmax/argmin also returns the values of these variables at the calculated observation numbers. If by(varlist) is specified, then argmax/argmin does the above for each group implied by these variables (excluding missing values).

Max/min values and observation numbers are put in return matrix r(values), along with any by and eval variables. If any of the by variables are string, their values will be replaced by integer values in the r(values) matrix. If any of the eval variables are string, their values will be the missing value "." in the r(values) matrix.

Example usage

. sysuse auto
(1978 Automobile Data)

. argmax price

. matrix list r(values)

r(values)[1,2]
    obs_num    price
r1       13    15906

. argmax price , eval(rep78)

. matrix list r(values)

r(values)[1,3]
    obs_num    price    rep78
r1       13    15906        3

. argmax price , by(rep78)

. matrix list r(values)

r(values)[5,3]
    obs_num    price    rep78
r1       48     4934        1
r2       12    14500        2
r3       13    15906        3
r4       55     9735        4
r5       74    11995        5

. argmax price , by(rep78) eval(mpg)

. matrix list r(values)

r(values)[5,4]
    obs_num    price    rep78      mpg
r1       48     4934        1       18
r2       12    14500        2       14
r3       13    15906        3       21
r4       55     9735        4       25
r5       74    11995        5       17

Author

James Fiedler (jrfiedler at gmail dot com)

stata_argmax's People

Contributors

jrfiedler avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

crisortiz92

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.