Announcement

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

  • How can I find maximal value of one variable between dates

    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	62.6 KB
ID:	1641641


    From the screenshot how can I find max cr between admitdate and disdate
    Thank you

  • #2
    to find the longest gap between admitdate and disdate,
    Code:
    egen max = max(disdate-admitdate)
    EDIT: I just noticed the variable datediff, which you can summarize to get maximum value,
    Code:
    summarize datediff
    Last edited by Øyvind Snilsberg; 20 Dec 2021, 03:50.

    Comment


    • #3
      Thank you

      I mean finding the maximum of variable "cr" in certain interval (between disdate and admitdate)
      could it be possible?

      Comment


      • #4
        My bad - the following code should get you what you want,
        Code:
        egen max = max(cr), by(admitdate)
        EDIT: changed by variable.
        Last edited by Øyvind Snilsberg; 20 Dec 2021, 04:48.

        Comment


        • #5
          I mean how can I find the max "cr"
          for example the first admit is 25 mar 2019 to 13 apr 2019
          max "cr" is 1.44
          how can I find those value in every date interval?

          Comment


          • #6
            I may not have fully understood your question, but seems you need the max in rolling window. You may try asrol (available from ssc) for finding rolling window statistics. See this example.
            Code:
            clear
            input float(date cr)
            42616   .3488717
            42617   .2668857
            42618   .1366463
            42619 .028556867
            42620   .8689333
            42621   .3508549
            42622  .07110509
            42623  .32336795
            42624   .5551032
            42625    .875991
            end
            
            * Find max of cr in a window of 15 dates
            asrol cr, stat(max) window(date 15) min(14)
              +----------------------------------+
                 |      date         cr    cr_max15 |
                 |----------------------------------|
              1. | 04sep2076   .2047095           . |
              2. | 05sep2076   .8927587           . |
              3. | 06sep2076   .5844658           . |
              4. | 07sep2076   .3697791           . |
              5. | 08sep2076   .8506309           . |
                 |----------------------------------|
              6. | 09sep2076   .3913819           . |
              7. | 10sep2076   .1196613           . |
              8. | 11sep2076   .7542434           . |
              9. | 12sep2076   .6950234           . |
             10. | 13sep2076   .6866152           . |
                 |----------------------------------|
             11. | 14sep2076   .9319346           . |
             12. | 15sep2076   .4548882           . |
             13. | 16sep2076   .0674011           . |
             14. | 17sep2076   .3379889    .9319346 |
             15. | 18sep2076   .9748848   .97488481 |
                 |----------------------------------|
             16. | 19sep2076   .7264384   .97488481 |
             17. | 20sep2076   .0454151   .97488481 |
             18. | 21sep2076   .7459667   .97488481 |
             19. | 22sep2076   .4961259   .97488481 |
             20. | 23sep2076   .7167162   .97488481 |
                 |----------------------------------|
             21. | 24sep2076    .859742   .97488481 |
             22. | 25sep2076   .1340756   .97488481 |
             23. | 26sep2076   .4884419   .97488481 |
             24. | 27sep2076   .8712187   .97488481 |
             25. | 28sep2076   .7664683   .97488481 |
                 |----------------------------------|
             26. | 29sep2076   .2512555   .97488481 |
             27. | 30sep2076   .1663648   .97488481 |
             28. | 01oct2076   .7437958   .97488481 |
             29. | 02oct2076   .9805113   .98051131 |
             30. | 03oct2076   .7295772   .98051131 |
                 |----------------------------------|
             31. | 04oct2076   .9011049   .98051131 |
             32. | 05oct2076   .2643649   .98051131 |
             33. | 06oct2076   .8856509   .98051131 |
             34. | 07oct2076    .882112   .98051131 |
             35. | 08oct2076    .748933   .98051131 |
                 |----------------------------------|
             36. | 09oct2076   .9196262   .98051131 |
             37. | 10oct2076   .6934533   .98051131 |
             38. | 11oct2076   .2154026   .98051131 |
             39. | 12oct2076   .8285888   .98051131 |
             40. | 13oct2076   .0442154   .98051131 |
                 |----------------------------------|
             41. | 14oct2076   .8630378   .98051131 |
             42. | 15oct2076   .3526046   .98051131 |
             43. | 16oct2076   .7720399   .98051131 |
             44. | 17oct2076   .5861199   .91962624 |
             45. | 18oct2076   .3227766   .91962624 |
                 |----------------------------------|
             46. | 19oct2076   .1729307   .91962624 |
             47. | 20oct2076   .8053644   .91962624 |
             48. | 21oct2076   .3060019   .91962624 |
             49. | 22oct2076   .2190997   .91962624 |
             50. | 23oct2076    .724731   .91962624 |
                 +----------------------------------+
            more on asrol can be found here https://fintechprofessor.com/2017/10...tics-in-stata/
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment

            Working...
            X