Stata sort by group

    how to sort variables in stata
    how to order variables in stata
    how to categorize variables in stata
    how to sort by two variables in stata
  • How to sort variables in stata
  • Stata sort descending...

    Sort, by, bysort, egen

    Sort order

    Not only could it be useful, but crucial, to sort your observations in a particular way when cleaning or creating outcomes.

    You can use the command in Stata to acheive this.

    Stata sort by two variables

  • Stata sort by two variables
  • List stata
  • Stata sort descending
  • Stata sort ascending
  • Stata sort variables alphabetically
  • Of course you can order your observation based on ordering one variable, but you can go further and sort your data on multiple variables. For example if you have a long dataset that contains two variables person id and survey round and for each person it has three survey rounds, then if you you will sort the data by person and within each person you will sort by the survey rounds.

    1. sorts observations in ascending order (i.e.

      lowest to highest)

    2. Missing values in stata are equivalent to infinity and thus will be sorted to the bottom of your sort if they exist
    1. You can flip the order you sort by using and using a negative sign in front of the variable name (i.e.

      sort largest to smallest

    1. If the observations of the variables you sort on are not unique, Stata will randomize their order in a new randomization every time you sort (i.e. you will not get a consistent orde

        how to categorize continuous variable in stata
        variables in stata