Announcement

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

  • Formatting a ITSA graph

    Hi. I would like to create the graph on the left. My code below, however, creates the graph on the right. I am unable to take off the bits above and below the graph ("Intervention starts..." and "GEE model...."). I am also unable to remove the fitted value line and add the lfit line to this.

    Any help in doing so will be very much appreciated.


    Click image for larger version

Name:	Sample graph1.png
Views:	1
Size:	174.6 KB
ID:	1766693


    Code:
    *code
    
    xtset con_id week_num
    
    xtitsa week_doctele i.age_cat i.doc_desig i.gender_cat i.department_cat i.LVPexp_cat ///
    week_num, single trperiod(78; 114) posttrend figure (legend(order(1 "observed" 2 "fitted values") size(small)) title("Hyderabad")             ///
    ytitle("Number of consultations") ylabel(#4, labsize(small) angle(horizontal)) ///
    xline(145) xlab(35 "(1 Jan '22 - 29 Jun '23)" 95 "(30 June, 2023 - 5 Mar, 2024)" 127 "(6 Mar, 2024 - 31 Jul, 2024)", noticks labsize (vsmall)) ///
    xtick(`tickcall',  tlength(*2)) xline(78) xline(114) scheme(s1color))                 ///        
     replace 
     
    
    
    *data
    
    input long con_id float(week_num week_doctele age_cat) byte doc_desig float(gender_cat department_cat LVPexp_cat)
    1 118  .03448276 2 1 1 6 1
    1 119  .01724138 2 1 1 6 1
    1 120  .01724138 2 1 1 6 1
    1 121  .03448276 2 1 1 6 1
    1 126  .03448276 2 1 1 6 1
    1 128  .01754386 2 1 1 6 1
    1 131  .05263158 2 1 1 6 1
    1 135 .071428575 2 1 1 6 1
    2   5  .12068965 2 3 2 8 1
    2   6  .05172414 2 3 2 8 1
    2   7  .05172414 2 3 2 8 1
    2   8  .12068965 2 3 2 8 1
    2   9   .1754386 2 3 2 8 1
    2  11  .19298245 2 3 2 8 1
    2  13  .24561404 2 3 2 8 1
    2  15   .2105263 2 3 2 8 1
    2  17  .22807017 2 3 2 8 1
    2  19  .16949153 2 3 2 8 1
    2  20  .15254237 2 3 2 8 1
    2  21  .10169491 2 3 2 8 1
    2  23  .22413793 2 3 2 8 1
    2  24  .14035088 2 3 2 8 1
    2  25   .1754386 2 3 2 8 1
    2  26  .19298245 2 3 2 8 1
    2  27  .07017544 2 3 2 8 1
    2  28  .24561404 2 3 2 8 1
    2  29  .05263158 2 3 2 8 1
    2  30  .15789473 2 3 2 8 1
    2  31  .13793103 2 3 2 8 1
    2  32  .25862068 2 3 2 8 1
    2  33   .0862069 2 3 2 8 1
    2  34   .1551724 2 3 2 8 1
    2  35   .1551724 2 3 2 8 1
    2  36   .2413793 2 3 2 8 1
    2  37  .10344828 2 3 2 8 1
    2  38   .1551724 2 3 2 8 1
    2  39  .13793103 2 3 2 8 1
    2  40  .10344828 2 3 2 8 1
    2  41  .10344828 2 3 2 8 1
    2  42  .12068965 2 3 2 8 1
    2  43   .1724138 2 3 2 8 1
    2  44  .10526316 2 3 2 8 1
    2  45  .12280702 2 3 2 8 1
    2  46  .19298245 2 3 2 8 1
    2  47  .12280702 2 3 2 8 1
    2  48  .14035088 2 3 2 8 1
    2  49  .05263158 2 3 2 8 1
    2  50  .12280702 2 3 2 8 1
    2  51   .2105263 2 3 2 8 1
    2  52  .12280702 2 3 2 8 1
    2  53   .1754386 2 3 2 8 1
    2  54  .12280702 2 3 2 8 1
    2  55   .2631579 2 3 2 8 1
    2  57  .08064516 2 3 2 8 1
    2  59   .2580645 2 3 2 8 1
    2  61   .1935484 2 3 2 8 1
    2  62  .06451613 2 3 2 8 1
    2  63  .06451613 2 3 2 8 1
    2  64  .12903225 2 3 2 8 1
    2  65  .11290322 2 3 2 8 1
    2  66  .09836066 2 3 2 8 1
    2  67   .1147541 2 3 2 8 1
    2  68  .13114753 2 3 2 8 1
    2  69  .08196721 2 3 2 8 1
    2  72  .21311475 2 3 2 8 1
    2  73  .06557377 2 3 2 8 1
    2  75   .1967213 2 3 2 8 1
    2  76   .1147541 2 3 2 8 1
    2  77  .09836066 2 3 2 8 1
    2  78  .18032786 2 3 2 8 1
    2  79  .18333334 2 3 2 8 1
    2  81         .2 2 3 2 8 1
    2  82        .15 2 3 2 8 1
    2  83        .15 2 3 2 8 1
    2  84  .18333334 2 3 2 8 1
    2  85  .18644068 2 3 2 8 1
    2  87    .220339 2 3 2 8 1
    2  89   .3050847 2 3 2 8 1
    2  90  .16949153 2 3 2 8 1
    2  91  .20338982 2 3 2 8 1
    2  93  .13559322 2 3 2 8 1
    2  96    .220339 2 3 2 8 1
    2  97    .220339 2 3 2 8 1
    2  98  .18644068 2 3 2 8 1
    2  99  .15254237 2 3 2 8 1
    2 102  .16949153 2 3 2 8 1
    2 103  .15254237 2 3 2 8 1
    2 104  .20338982 2 3 2 8 1
    2 109  .13793103 2 3 2 8 1
    2 111   .1724138 2 3 2 8 1
    2 113  .29310346 2 3 2 8 1
    2 114  .13793103 2 3 2 8 1
    2 116  .18965517 2 3 2 8 1
    2 117  .20689656 2 3 2 8 1
    2 118   .2413793 2 3 2 8 1
    2 119   .1724138 2 3 2 8 1
    2 120   .0862069 2 3 2 8 1
    2 121  .13793103 2 3 2 8 1
    2 122  .18965517 2 3 2 8 1
    2 123  .18965517 2 3 2 8 1
    Attached Files

  • #2
    you might get more help with a dataex that will produce results.

    Comment


    • #3
      George Ford Hi George. I apologize, I thought the data sample above would suffice. My dataset has about 4,500 observations and I'm unsure how to provide a data sample or the entire dataset to produce results. Could you please guide me on this?

      Comment


      • #4
        not sure. tricky given large sample and convergence issues. maybe just a few observations per time period. find something that runs and gets you close to what you've got (visually).

        Comment


        • #5
          George Ford Hi George. Here's a sample that works with the code below to generates the graph in black. I'm looking to create the graph in green. I'd greatly appreciate any help on this.


          Code:
          
          xtset con_id week_num
          
          xtitsa week_doctele, single trperiod(29; 47) posttrend figure (legend(order(1 "observed" 2 "fitted values") size(small)) title("Hyderabad")             ///
          ytitle("Number of consultations") ylabel(#4, labsize(small) angle(horizontal)) ///
           xlab(20 "(1 Jan '22 - 29 Jun '23)" 35 "(30 June, 2023 - 5 Feb, 2024)" 65 "(6 Feb, 2024 - 31 Jul, 2024)", noticks labsize (vsmall)) ///
          xtick(`tickcall',  tlength(*2)) xline(29) xline(47) scheme(s1color))                 ///        
           replace 
          
          input long con_id float(week_num week_doctele age_cat gender_cat) byte doc_desig float(department_cat LVPexp_cat)
           5  1   .6153846 3 2 4 2 3
          12  1   .7692308 2 2 1 7 1
           4  2  .07692308 2 1 5 2 2
          10  3   .3846154 3 1 1 3 2
           4  4   .9230769 2 1 5 2 2
          12  4   .9230769 2 2 1 7 1
          10  5  .15384616 3 1 1 3 2
           5  6   .7692308 3 2 4 2 3
           1  8          1 3 2 2 7 2
           1  9  .53846157 3 2 2 7 2
           5 10   .9230769 3 2 4 2 3
          11 10  .23076923 2 2 2 4 1
          10 11   .8461539 3 1 1 3 2
          13 11  1.6153846 3 1 3 7 3
           6 12  .53846157 2 1 5 6 2
          10 12   .6153846 3 1 1 3 2
          15 12   .8461539 2 2 2 2 2
           4 13  .53846157 2 1 5 2 2
          10 13  .53846157 3 1 1 3 2
          12 13   2.692308 2 2 1 7 1
           4 14   .9230769 2 1 5 2 2
           8 16   .4615385 2 1 2 4 1
           4 17  1.5384616 2 1 5 2 2
          12 17  1.5384616 2 2 1 7 1
           1 18   .7692308 3 2 2 7 2
          12 18   .8461539 2 2 1 7 1
          13 18  1.6923077 3 1 3 7 3
           1 19   .7692308 3 2 2 7 2
           3 19  1.6153846 2 1 1 2 1
           8 19   .6923077 2 1 2 4 1
           1 21   .9230769 3 2 2 7 2
           3 21  1.3076923 2 1 1 2 1
          13 21  1.3846154 3 1 3 7 3
           5 22   .5833333 3 2 4 2 3
           1 23   .9166667 3 2 2 7 2
           9 24  .16666667 3 1 2 5 1
           6 25          4 2 1 5 6 2
           6 26        1.5 2 1 5 6 2
           1 27        1.5 3 2 2 7 2
           4 27   .8333333 2 1 5 2 2
          11 28   .8333333 2 2 2 4 1
           1 29  1.5833334 3 2 2 7 2
           3 29  1.6666666 2 1 1 2 1
           8 31   .6428571 2 1 2 4 1
           8 32   .7857143 2 1 2 4 1
          12 32  1.3571428 2 2 1 7 1
          11 33         .5 2 2 2 4 1
           1 34          1 3 2 2 7 2
          12 35   .7142857 2 2 1 7 1
          15 35  1.2142857 2 2 2 2 2
          15 36   .6428571 2 2 2 2 2
           1 38         .5 3 2 2 7 2
          11 38  1.1428572 2 2 2 4 1
           8 39   .3571429 2 1 2 4 1
           8 40   .3571429 2 1 2 4 1
           9 42   .4285714 3 1 2 5 1
          11 43  1.1428572 2 2 2 4 1
           8 44   .5714286 2 1 2 4 1
          11 45  1.1428572 2 2 2 4 1
          11 47  1.2857143 2 2 2 4 1
          15 48  1.4285715 2 2 2 2 2
           6 49   .7857143 2 1 5 6 2
           4 50   .4285714 2 1 5 2 2
           4 51   .8571429 2 1 5 2 2
           3 53   .6428571 2 1 1 2 1
           9 56   .2857143 3 1 2 5 1
           6 58   .7857143 2 1 5 6 2
           4 59   .7857143 2 1 5 2 2
          15 59   .9285714 2 2 2 2 2
           1 60  1.1428572 3 2 2 7 2
           4 60        1.5 2 1 5 2 2
           5 61   .4285714 3 2 4 2 3
          15 63   .9285714 2 2 2 2 2
           8 64   .2142857 2 1 2 4 1
          12 65  1.4285715 2 2 1 7 1
          12 66  1.2142857 2 2 1 7 1
          15 66   .7857143 2 2 2 2 2
          11 67         .5 2 2 2 4 1
           4 68 .071428575 2 1 5 2 2
           4 69   .2857143 2 1 5 2 2
          12 69  1.5714285 2 2 1 7 1
           3 70   .4285714 2 1 1 2 1
          15 74          1 2 2 2 2 2
          16 74 .071428575 2 1 1 2 1
           4 75   .6428571 2 1 5 2 2
           8 75   .7857143 2 1 2 4 1
           8 76   .4285714 2 1 2 4 1
          15 76   .6428571 2 2 2 2 2
           1 77   .5714286 3 2 2 7 2
           4 77   .3571429 2 1 5 2 2
           4 78   .7142857 2 1 5 2 2
          15 78   .8571429 2 2 2 2 2
           5 79         .5 3 2 4 2 3
          15 79   .2857143 2 2 2 2 2
          13 80   .4285714 3 1 3 7 3
          13 82  1.0714285 3 1 3 7 3
           3 83   .2142857 2 1 1 2 1
          13 83  1.3571428 3 1 3 7 3
           1 84   .8571429 3 2 2 7 2
           3 84   .7857143 2 1 1 2 1

          Click image for larger version

Name:	ITSA formatting.png
Views:	1
Size:	182.6 KB
ID:	1766945


          Click image for larger version

Name:	Sample graph.png
Views:	2
Size:	177.1 KB
ID:	1766944





          Comment


          • #6
            Code:
            note("") subtitle("")
            should remove the note and subtitle. This is a simple scatter-plot, why not just use twoway to create the graph that you need? I am unable to do this for you for now. Note that xtitsa is from SSC, as you are asked to explain (FAQ Advice #12).
            Last edited by Andrew Musau; 04 Nov 2024, 09:19.

            Comment


            • #7
              Andrew Musau Thanks. xtitsa uses twoway options in the form of figure[(twoway_options)]. I just haven't been able to figure them out to get the graph I want.

              Comment


              • #8
                You should contact Ariel Linden at lindenconsulting. It's his code and maybe he can figure it out. His paper shows linear lines, but I can't sort it out.

                Here's what Andrew was alluding to.

                Code:
                twoway lfit week_doctele week_num if week_num<=28 || lfit week_doctele week_num if inrange(week_num,29,46) || lfit week_doctele week_num if week_num>=47 || scatter week_doctele week_num , xline(29 47)

                Comment

                Working...
                X