Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate Minimum value using index

    I want to generate a minimum value using the index. A part of the data attached in the table below, I want to calculate the minimum value of 'ASVI' value based on the 'index'. The desired calculation is shown in the column 'min'.
    Code:
     
    index Time SVI PSVI ASVI Min
    1 -3 0.97 0.75 0.22 -0.15
    1 -2 0.91 1.07 -0.15 -0.15
    1 -1 0.77 0.90 -0.12 -0.15
    1 0 0.99 0.95 0.03 -0.15
    1 1 1.20 1.10 0.10 -0.15
    2 -5 1.24 1.20 0.04 -0.18
    2 -4 1.17 0.82 0.35 -0.18
    2 -3 0.90 0.66 0.24 -0.18
    2 -2 0.88 1.06 -0.18 -0.18
    2 -1 0.79 0.90 -0.12 -0.18
    2 0 1.09 0.94 0.15 -0.18
    2 1 1.12 1.14 -0.02 -0.18
    3 -3 1.15 1.19 -0.04 -0.20
    3 -2 0.93 0.84 0.09 -0.20
    3 -1 0.83 0.68 0.15 -0.20
    3 0 0.86 1.06 -0.20 -0.20
    3 1 1.00 0.89 0.11 -0.20
    4 -2 0.86 0.99 -0.12 -0.17
    4 -1 1.18 1.12 0.06 -0.17
    4 0 1.02 1.19 -0.17 -0.17
    4 1 0.97 0.86 0.11 -0.17
    Thank you

  • #2
    Code:
    by index, sort: egen wanted = min(ASVI)
    Do take the time to master the -by:- prefix and -egen- command (and its many, very useful, functions) by reading the corresponding sections of the PDF documentation. It will not take very long to do that, and the time you invest will be amply repaid in short order. They are the tools you need to carry out most calculations that aggregate some statistic over a grouping variable.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment

    Working...
    X