Announcement

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

  • Fill in missing rows for dates

    Below, I have some survey data where we (wanted) respondents to answer for 30 straight days. Of course, many respondents missed a handful of days here and there.

    Right now, we just have a counter for each survey someone took. But, what I want to do is identify a respondent's non-response date(s), add that row back into the dataset, and include some flag for "nonresponse" or something like that as well, so I can identify these rows later. How can I do this?




    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3 pptid float(survey_date surveynum)
    "100" 21769 1
    "100" 21770 2
    "100" 21771 3
    "100" 21772 4
    "100" 21773 5
    "100" 21774 6
    "100" 21775 7
    "100" 21776 8
    "100" 21777 9
    "100" 21778 10
    "100" 21779 11
    "100" 21781 12
    "100" 21782 13
    "100" 21783 14
    "100" 21784 15
    "100" 21785 16
    "100" 21786 17
    "100" 21787 18
    "100" 21788 19
    "100" 21789 20
    "100" 21790 21
    "100" 21791 22
    "100" 21793 23
    "100" 21794 24
    "100" 21795 25
    "100" 21796 26
    "100" 21797 27
    "100" 21798 28
    "200" 21806 1
    "200" 21807 2
    "200" 21808 3
    "200" 21809 4
    "200" 21810 5
    "200" 21811 6
    "200" 21812 7
    "200" 21813 8
    "200" 21814 9
    "200" 21815 10
    "200" 21816 11
    "200" 21817 12
    "200" 21818 13
    "200" 21819 14
    "200" 21820 15
    "200" 21821 16
    "200" 21822 17
    "200" 21824 18
    "200" 21825 19
    "200" 21827 20
    "200" 21828 21
    "200" 21829 22
    "200" 21830 23
    "200" 21831 24
    "200" 21832 25
    "200" 21833 26
    "200" 21834 27
    "200" 21835 28
    "300" 21869 1
    "300" 21870 2
    "300" 21871 3
    "300" 21872 4
    "300" 21873 5
    "300" 21874 6
    "300" 21875 7
    "300" 21876 8
    "300" 21877 9
    "300" 21878 10
    "300" 21879 11
    "300" 21880 12
    "300" 21881 13
    "300" 21882 14
    "300" 21883 15
    "300" 21884 16
    "300" 21885 17
    "300" 21886 18
    "300" 21887 19
    "300" 21888 20
    "300" 21889 21
    "300" 21890 22
    "300" 21891 23
    "300" 21892 24
    "300" 21893 25
    "300" 21895 26
    "300" 21896 27
    "300" 21897 28
    "300" 21898 29
    end
    format %td survey_date

  • #2
    not sure I completely understand, but see
    Code:
    h fillin

    Comment


    • #3
      Originally posted by Rich Goldstein View Post
      not sure I completely understand, but see
      Code:
      h fillin
      From what I understand, -fillin- relies on a global date min/max, which I would not want. I would want to essentially 'fillin' for each individual respondent's own respective date range.

      Comment


      • #4
        You could use tsfill for this. Alternatively, you could use fillin, as suggested, after tagging the maximum and minimum values per panel, with an additional deletion step.

        Code:
        egen id= group(pptid), label
        xtset id survey_date
        tsfill 
        gen missing= missing(pptid)
        order id pptid
        Res.:

        Code:
        . l id survey_date-missing, sepby(id)
        
             +--------------------------------------+
             |  id   survey_~e   survey~m   missing |
             |--------------------------------------|
          1. | 100   08aug2019          1         0 |
          2. | 100   09aug2019          2         0 |
          3. | 100   10aug2019          3         0 |
          4. | 100   11aug2019          4         0 |
          5. | 100   12aug2019          5         0 |
          6. | 100   13aug2019          6         0 |
          7. | 100   14aug2019          7         0 |
          8. | 100   15aug2019          8         0 |
          9. | 100   16aug2019          9         0 |
         10. | 100   17aug2019         10         0 |
         11. | 100   18aug2019         11         0 |
         12. | 100   19aug2019          .         1 |
         13. | 100   20aug2019         12         0 |
         14. | 100   21aug2019         13         0 |
         15. | 100   22aug2019         14         0 |
         16. | 100   23aug2019         15         0 |
         17. | 100   24aug2019         16         0 |
         18. | 100   25aug2019         17         0 |
         19. | 100   26aug2019         18         0 |
         20. | 100   27aug2019         19         0 |
         21. | 100   28aug2019         20         0 |
         22. | 100   29aug2019         21         0 |
         23. | 100   30aug2019         22         0 |
         24. | 100   31aug2019          .         1 |
         25. | 100   01sep2019         23         0 |
         26. | 100   02sep2019         24         0 |
         27. | 100   03sep2019         25         0 |
         28. | 100   04sep2019         26         0 |
         29. | 100   05sep2019         27         0 |
         30. | 100   06sep2019         28         0 |
             |--------------------------------------|
         31. | 200   14sep2019          1         0 |
         32. | 200   15sep2019          2         0 |
         33. | 200   16sep2019          3         0 |
         34. | 200   17sep2019          4         0 |
         35. | 200   18sep2019          5         0 |
         36. | 200   19sep2019          6         0 |
         37. | 200   20sep2019          7         0 |
         38. | 200   21sep2019          8         0 |
         39. | 200   22sep2019          9         0 |
         40. | 200   23sep2019         10         0 |
         41. | 200   24sep2019         11         0 |
         42. | 200   25sep2019         12         0 |
         43. | 200   26sep2019         13         0 |
         44. | 200   27sep2019         14         0 |
         45. | 200   28sep2019         15         0 |
         46. | 200   29sep2019         16         0 |
         47. | 200   30sep2019         17         0 |
         48. | 200   01oct2019          .         1 |
         49. | 200   02oct2019         18         0 |
         50. | 200   03oct2019         19         0 |
         51. | 200   04oct2019          .         1 |
         52. | 200   05oct2019         20         0 |
         53. | 200   06oct2019         21         0 |
         54. | 200   07oct2019         22         0 |
         55. | 200   08oct2019         23         0 |
         56. | 200   09oct2019         24         0 |
         57. | 200   10oct2019         25         0 |
         58. | 200   11oct2019         26         0 |
         59. | 200   12oct2019         27         0 |
         60. | 200   13oct2019         28         0 |
             |--------------------------------------|
         61. | 300   16nov2019          1         0 |
         62. | 300   17nov2019          2         0 |
         63. | 300   18nov2019          3         0 |
         64. | 300   19nov2019          4         0 |
         65. | 300   20nov2019          5         0 |
         66. | 300   21nov2019          6         0 |
         67. | 300   22nov2019          7         0 |
         68. | 300   23nov2019          8         0 |
         69. | 300   24nov2019          9         0 |
         70. | 300   25nov2019         10         0 |
         71. | 300   26nov2019         11         0 |
         72. | 300   27nov2019         12         0 |
         73. | 300   28nov2019         13         0 |
         74. | 300   29nov2019         14         0 |
         75. | 300   30nov2019         15         0 |
         76. | 300   01dec2019         16         0 |
         77. | 300   02dec2019         17         0 |
         78. | 300   03dec2019         18         0 |
         79. | 300   04dec2019         19         0 |
         80. | 300   05dec2019         20         0 |
         81. | 300   06dec2019         21         0 |
         82. | 300   07dec2019         22         0 |
         83. | 300   08dec2019         23         0 |
         84. | 300   09dec2019         24         0 |
         85. | 300   10dec2019         25         0 |
         86. | 300   11dec2019          .         1 |
         87. | 300   12dec2019         26         0 |
         88. | 300   13dec2019         27         0 |
         89. | 300   14dec2019         28         0 |
         90. | 300   15dec2019         29         0 |
             +--------------------------------------+
        
        .

        Comment

        Working...
        X