Announcement

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

  • Calculating ReAdmission: Simple Question/New to Stata

    The dataset: ID, admission date, ....2 other columns. There are multiple admission dates for the same ID. For example:
    ID: 1, 1,1,2,3,3,
    Date: 2-May-1998, 4-Sept-1998, 1-Oct-1998, 1-Mar-1998, etc.

    Goal: Make a dummy variable that says whether each discharge has a readmission. Basically: if the next date is within 30 days of the index claim. This has to be done for each unique ID.

    Any help is VERY APPRECIATED!!


  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id date)
    1 14001
    1 14126
    1 14153
    2 13939
    3 14031
    3 14042
    end
    format %td date
    
    by id (date), sort: gen is_readmission = date-date[_n-1] < 30
    by id (is_readmission), sort: gen had_readmission = is_readmission[_N]
    sort id date
    list, noobs sepby(id)
    For future reference, please post sample data by using the -dataex- command, as I have done above. It enables those who want to help you to quickly import into Stata an exact replica of the data you want us to use.

    Notes:

    1. Note that I have created the date variable as a numeric Stata internal format date variable. The code will not work with string variables that humans read as dates, nor with numeric values like 02051998 that a human could possibly read as 2may1998. If your dates are not set up that way, install Nick Cox's -numdate- command (-ssc install numdate-) and use that to convert whatever you have to Stata internal format dates.

    2. The code generates two indicator variables. One tags each observation as either being a readmission or not. The other, which is constant within id, identifies whether that id had any readmissions or not.

    3. The Stata terminology for what you referred to as "columns" is variables. While Stata data sets sometimes look like spreadsheets, they have very different properties from spreadsheets and it is best to avoid using spreadsheet terminology to describe or even think about them. Whatever skills and habits you may have developed with spreadsheets will have, at best, limited usefulness in Stata, and often they actually get in the way.

    Comment


    • #3
      Thank you so much! I definitely learned a lot from both the code and your notes. I will use your notes in the future re: future posts. Thank you again.

      Comment


      • #4
        Dear Clyde

        I have a similar problem which I am trying to sort and came across this post but it doesn't really work for me, I am looking to create readmission by id and finaldop variables. the ID can appear multiple times in the dataset and in some instances appears on the same date twice which I think is an error in the data. I want to create a readmission variable within 60 days from the index "finaldop" ( it stands for date of procedure) after dropping for the duplicate entry on the same date of the procedure if there are any. I am also interested in counting the difference in days between the index procedure to the second or third procedure within 60 days.
        I have tried the above code but the is_readmission doesn't seem to be giving me the correct data. I have generated the variable "first" which tells me how many times id appears in the dataset in date order. Please see the data example below. your help is much appreciated

        input str64 id float(finaldop first)
        "00000CDABBAF342888B204DCBAEC16C6C92547A2E3571FF46 54E9245BB96B669" 21762 1
        "000021a24d1c3ec2de3c7c0d58b6a45ca82247123fdff7a73 308b036c31c5471" 17582 1
        "000054D66A3885ED1239FEF86C1C556E96F40FDD1EE53D0D2 3642A967B1C269B" 21768 1
        "00006c99896cc1db9fa7916847ed8800032f5369940b32ad3 3aa557904efa073" 19983 1
        "00006e5153758792ea129ccce148ea9c7ffa9379fc697ac70 55b6424171eb466" 20135 1
        "000070c5cd8271abab1659980ddf4f74040c4e0638b0e4e5d 9779f800aadac28" 17391 1
        "0000789d88394c4d9bcb6e52009f7e6bb78d5dd2d161b9804 151fc947a2c9760" 20779 1
        "00013334f292c1e14eae804adbb89c02f0f1d69592f256401 38a48c173edb7e9" 17219 1
        "00014CF53BE9EE2B845E6903C01ECB1D9A6B412E684087165 B44AABB0E89F324" 21951 1
        "0001643b9272dd7e9661ea7450fa8bfbb7ac60add38d60e83 9db21b498d442ba" 21530 1
        "000176DC3B7DD51EEEE482F0888A3C4875EA6062B268378B9 18A460DA3B8A5AA" 21812 1
        "00019242ecf062baba367f1eb25ce4c27f164a227cbabb321 c6e8f39ae67c9fa" 19723 1
        "0001dd537b25a139b8582f2cb6edec0ef6d83f954aeab1e8c 21d8606e2697812" 20464 1
        "0001f47977e8c6e385c6f3cc297e0fbc0cf7923b3f54ea13c 420fc3ce98e162b" 18701 1
        "000224f041bfe3543f4e63f7705ffccdee457a673c7e1c091 03bff12e0a4e5cc" 20524 1
        "00025ff5f8f4619ebabc394323a02764bf8f2023b69e98f31 ea7034b6e13f842" 21220 1
        "0002a039cec22ef5e0efb4f42b88eccebf53eff1fb098f5fb 1bbc505ced43987" 21234 1
        "0002a97cd0078046f95614b2904a7806470b5facab8cb46be fe2639dee976b6d" 18703 1
        "0002b2e1b58f322f14ef2d4055c6b8a8dc4a5ff14532c8bc4 2b22dedae233327" 17126 1
        "0002c709e66db85b3b0bf666abf4e01f2d5937c192fe240e7 27848f629f2b32c" 20338 1
        "0002f6ce5335640e11d5cf86e1b50860b9d3ffc18d7906f75 1026e18e7b2a53c" 21312 1
        "000310342e152003bfa74d61b8f1ed5cf23cad2b42e6e3a6a 243bb100b79aed4" 20566 1
        "000310342e152003bfa74d61b8f1ed5cf23cad2b42e6e3a6a 243bb100b79aed4" 20739 2
        "000312786cfb99ec96f3868fa7d523c756cb01fd9fc851829 e33ac4eced1c7bd" 18592 1
        "00038AD5A88FA58C2B9676BAD609B97007778BFB12EE5B37F B08744CB5636492" 21942 1
        "00039a55799e9d4d7ee4e7bcae658224d23c73dbfb9bf8f29 24473d1fed9f623" 20167 1
        "0003ae2dc79828ce559dfe5298617d36e49e6357ecedf9e3a 83965c8305c3194" 19841 1
        "0003d0eb2c3a2b245c0cb751b1bddaff55b3329568c83beb1 e4c4a90bb86e2d2" 21010 1
        "0004492e0004bcb814f64aa57aaca714688d01780c8e3cf8a 2c4ffe6510b109f" 20961 1
        "00045d3267af709d577f7eca88c4a04e782a2ef2bc2487aa6 ce1f044d7df7672" 18177 1
        "00049f60cc833925e168a53f58fac92c8614bb850bb04a1af a3a76951b049443" 17185 1
        "00049f60cc833925e168a53f58fac92c8614bb850bb04a1af a3a76951b049443" 17185 2
        "00049f60cc833925e168a53f58fac92c8614bb850bb04a1af a3a76951b049443" 17241 3
        "00049fd2ac5005109b9a2e2acaaea65a79e4dbaf2921a0e45 5d6d98b83b8f235" 20090 1
        "0004a93589dd737518bd3f9754a8c4e48cc25714c41e19afb 8b9a50cca3c7bd0" 18660 1
        "0004f81d3c0138383ec25f7bdd343d55fff0bf33830679f73 f70099797e5af5e" 20452 1
        "0004f9e13418b0b82cf77e112a60983102df2d5c1fc1bac5f 3d2046505bb4ec4" 20909 1
        "00050bafd31b0f56ad8d6560ff56fe2623e097ba42b512a0e 66d994a8f2ac9ec" 21500 1
        "0005330106a28cbae8e59fe217d7b7a1e1dde16b29c05b05e a0ff078f221fd10" 17332 1
        "00054e0302d4947f184c0eb82a3f9494f25122c3a14b8cb0a eeade892255673c" 21252 1
        "0005596aeb1102fd1d7f2cc7e7e4ff97b5356f22903f98f92 d15d33a4424345e" 21217 1
        "00058a72b58de81ad7bfdce20cd6dc282cd25f04a9a8d4c4e f8a21abd4885606" 20202 1
        "0005c6aaacf413b13ea7f85d40544a9fc213690e0e550d697 84e66ea70fee027" 17036 1
        "0005e7492c55a9466bf9a49b038a7d5039be86d2fddcf9228 188a5435e6a47e4" 18288 1
        "0005e79f6c5ee6e8a1a22bb3ea9a9d845ca83efd100231005 b1dc079e016a171" 18539 1
        "0005e79f6c5ee6e8a1a22bb3ea9a9d845ca83efd100231005 b1dc079e016a171" 19424 2
        "0005f623ecb85f421e71a87634d4e792b8d81eea1c958af17 1eb2e007b8fc33d" 19680 1
        "00062fe16783284aa767d368fd13156009ea64ae801a8130e e4b5015f5e89e9c" 20893 1
        "0006314071d5158ef807806939b1b914960d14ff062d2bf46 53da85ae2147142" 18191 1
        "0006507F210FD9DEA41D60D99C61844FF2326B3659839BFD7 B30EB0A94BAF34D" 21894 1
        "0006507F210FD9DEA41D60D99C61844FF2326B3659839BFD7 B30EB0A94BAF34D" 21936 2
        "00066d0b2d97fcc07f4a56c57529dd0ca4733f24286417e3c f78cada49684d01" 17799 1
        "000674714bbdf129b03fd3d52c0cd3c779765a50ad3f47a4c e9508acbfa11acf" 20319 1
        "00067C84FC5AC2BE49907AC1228650DA582D6DEFAD772E6CB 456A72016DC0DCC" 21851 1
        "0006c9ba28c2e22e5dd85ad17f42ec5de4c7ba5c7c5b73505 ba69d23e583d7ee" 19598 1
        "0006d2a6bbe84924f16b45fd2abf333807f23731aa9a727e5 3a0bb3fc5c883ee" 19764 1
        "0006d55d5cece211ab5dc7713e0197f4e6dd658ed216000ee 609c4233a39097b" 18974 1
        "0006f88b0e128be507b26cf6bb1223f2a15a3722b39620060 879bfc973dd1eba" 21283 1
        "0007157d660a9cae38c89acf284aac70d1b495b5243971255 922200e8d9882d9" 19871 1
        "00074c100231a270384862c16eb4afdafb9bcc317bc69b86d c90bc9080bfe4b2" 17658 1
        "000763b5e8be2ecf35ebbf5167306af3b035d827178b1e100 ec7a09835f1e27d" 17288 1
        "0007961be7502cfe81d772f9415cd0f9cdde50952922f71e2 5edd998eae0b958" 18046 1
        "00079a884487d7e9e4a59bd4b84ec5e78d4422b0ca7e562fa e14eab0ac3d6646" 21344 1
        "0007a729fdb825a80c281a06034e4886ba1cb6f3829d11732 4d51c578002b7a2" 20743 1
        "0007a729fdb825a80c281a06034e4886ba1cb6f3829d11732 4d51c578002b7a2" 20752 2
        "0007a7de19bb95d3f064ff09d84f2ea209769243127be90a6 5270dc2f29dfdb1" 21405 1
        "0007d8b000513cca8b3f9ffe84e53c3edc1311c41553ee5d1 9378f64d45d6e7e" 17646 1
        "0007e173333f18c405464882d505f9375bdc67d4a0f603a48 73575017be7f67c" 18724 1
        "00080c13f93976ff79646eebddb0103f8b43c3abf7dd33e0d f3ae57cee43078b" 20117 1
        "0008171405d064ed7fa69ab8a4681f90c423e90429671d8bc 93051d7a6f7e414" 19810 1
        "000850305d6dc7990bea1e69b4c2ce4f1d1ae00b814444a21 6a38ad63d736327" 17776 1
        "000863e4dae8e29d018706a47fe2388df865abc964e38229a 7edeb7bcc915d02" 18484 1
        "000889cbb7dc12beebd02835c94585dc9af276119adb08e09 ce3b7b1db82fe21" 20096 1
        "0008dc1f76f1705330f6df69ab920bcb7e952fb0cf99efae2 3aca1c3cf9b61ca" 20794 1
        "0008e540cbd4a79ab69693326fa1ee8e9a1acc313bd21884b 9ccba52f4b939ea" 19962 1
        "0008e684df6daa3cbe3ff42a0cb96b2f127d3c6abcc55f86c aa1cbab1cfed303" 17301 1
        "0008ec7f8ab6aa58c88c796d46c181799e2b3483c6b339b94 0eaa83dcdcab0b0" 20286 1
        "000934c211279ea7f6b819a647f5ffdf3ee100c7b9309b7de dd3260826441a97" 20137 1
        "00093d23093ea3d0fb76e0f8a3607f01a5aba3b39c965566a fbc8d975ebd70d9" 19075 1
        "00094665960a5d09338a3aa25ee1b38e25690abb9487100d7 d547659edbf6fc9" 20634 1
        "0009633bac4e7a558ebfaf97658077f2d823e2c8c8e27975e 01b1f28b81b13f1" 20486 1
        "000968262d8bc68ef773ad16ce2f7a2234006daa54e46fa60 b21b520fe494a04" 20885 1
        "000969328580102dba352f5f3f2dcc9536aa85b08a5b2b2f1 f594e884ca75511" 17958 1
        "0009700ede440c8f941ba7775182209e47d8826b81528c7c1 91bbd7a630b0528" 21459 1
        "0009949c94f9c04031ea8e3ab55d023ee9d94e8a8db856e49 a621e319efa25b9" 18584 1
        "0009949c94f9c04031ea8e3ab55d023ee9d94e8a8db856e49 a621e319efa25b9" 18780 2
        "0009949c94f9c04031ea8e3ab55d023ee9d94e8a8db856e49 a621e319efa25b9" 18815 3
        "0009949c94f9c04031ea8e3ab55d023ee9d94e8a8db856e49 a621e319efa25b9" 18821 4
        "0009a09ebcec465ac214a8791334d206edab3be049ea8c5bb f7aae24856db1d1" 19722 1
        "0009e11418af96d630d76ab5b4c094295c72b4d9bdbd34b02 44419c7179588af" 20507 1
        "0009f38f1671900d3b1c18893398acbb72e3b56ddb388fcb7 89e5b890eab1e80" 19887 1
        "0009f38f1671900d3b1c18893398acbb72e3b56ddb388fcb7 89e5b890eab1e80" 19927 2
        "000C85B8A35A2D6A6102210965F07A09295C166B318AC46B0 A1342BAC4CFECCA" 21758 1
        "000C88739C62C98A3F49B7030BFC78FFDAAED869BE6C96AA5 13E9C1B43F7468D" 21796 1
        "000CB7BB86627BB74AFD15B8176AAD29A01A28C524285F9D6 04B5547CD489DF9" 21825 1
        "000CEBADDD2CC95351E17DDE743DA12627EEA56F1B7A9E87C 4D1B39E535659DC" 21983 1
        "000D188C4F8D930BACCE67D25900F08CAF7CB1973B8AAD65C 316F99C8413407B" 21755 1
        "000EFC0855371F10317EAB106DCF43D0ED08BA93DA197208D EC0CE6728A490CD" 21715 1
        "000F26371554CB259CC47F5CAA91034D84ABA6ABC37AC5AAB 32D837277CDEB54" 21864 1
        "000a27c508aafd834419f50c6e9eb461a60b788b5fe35d079 9f1131a52dcfc8c" 19368 1
        end
        format %td finaldop
        [/CODE]
        ----------

        Comment


        • #5
          Well, you cannot have run exactly the code from #2: at the least you must have changed 30 to 60 and substituted finaldop for date. But on the assumption you did that, after dropping duplicate observations of id and finaldop, it runs in your example data without any error messages and produces results that, when verified by hand, are correct. In short, I cannot reproduce the problem you are reporting.

          So please post back showing the exact code you have run, a new data example in which incorrect results are produced, and show specifically the incorrect results you are getting and what you want them to be. Then perhaps I can troubleshoot.

          Comment

          Working...
          X