Announcement

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

  • mofd and twoway connected graph issue

    Hello,

    I use Stata 14.2. I am working on a cross-sectional dataset.
    I have used the command mofd to generate a month/year variable (which I called mydi) from a date variable (which I called dadis).
    When I tabulate the variable mydi, the categories shown (apr16 sep17 apr16 sep17) are correct. So far so good.
    The problem comes when I use the command twoway connected with the variable mydi. In the graph, the label for
    sep16 and sep17 showns oct16 and oct17 instead... Can you advice please?

    I am copying below an example of my dataset (including only relevant variables) a description of the variables, and the commands I use.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int id float ty int dadis float(mydi vol)
     69 1 20565 675  6
     45 1 20558 675  6
     49 1 20558 675  6
     44 1 20558 675  6
    110 1 20572 675  6
     74 1 20565 675  6
     90 2 20572 675 39
    112 2 20572 675 39
     34 2 20558 675 39
     18 2 20551 675 39
     16 2 20551 675 39
     65 2 20565 675 39
     64 2 20565 675 39
     88 2 20565 675 39
     78 2 20565 675 39
     66 2 20565 675 39
     99 2 20572 675 39
     12 2 20551 675 39
     98 2 20572 675 39
      6 2 20551 675 39
     96 2 20572 675 39
     32 2 20558 675 39
     38 2 20558 675 39
     17 2 20551 675 39
    106 2 20572 675 39
     50 2 20558 675 39
     31 2 20551 675 39
     60 2 20565 675 39
     62 2 20565 675 39
     92 2 20572 675 39
     93 2 20572 675 39
     73 2 20565 675 39
     94 2 20572 675 39
     77 2 20565 675 39
      4 2 20551 675 39
    113 2 20572 675 39
     47 2 20558 675 39
     61 2 20565 675 39
    109 2 20572 675 39
     89 2 20572 675 39
     46 2 20558 675 39
     76 2 20565 675 39
     97 2 20572 675 39
     39 2 20558 675 39
     51 2 20558 675 39
     22 3 20551 675  8
     37 3 20558 675  8
     63 3 20565 675  8
     20 3 20551 675  8
     33 3 20558 675  8
     57 3 20558 675  8
     52 3 20558 675  8
    100 3 20572 675  8
     15 4 20551 675  7
    107 4 20572 675  7
     43 4 20558 675  7
     10 4 20551 675  7
     72 4 20565 675  7
     36 4 20558 675  7
    102 4 20572 675  7
     48 5 20558 675  1
    345 1 20712 680 14
    382 1 20719 680 14
    413 1 20726 680 14
    371 1 20719 680 14
    268 1 20698 680 14
    349 1 20712 680 14
    415 1 20726 680 14
    412 1 20726 680 14
    347 1 20712 680 14
    328 1 20712 680 14
    353 1 20712 680 14
    299 1 20705 680 14
    401 1 20726 680 14
    279 1 20698 680 14
    264 2 20698 680 35
    341 2 20712 680 35
    322 2 20712 680 35
    265 2 20698 680 35
    350 2 20712 680 35
    335 2 20712 680 35
    359 2 20719 680 35
    411 2 20726 680 35
    295 2 20705 680 35
    334 2 20712 680 35
    396 2 20726 680 35
    270 2 20698 680 35
    302 2 20705 680 35
    402 2 20726 680 35
    269 2 20698 680 35
    348 2 20712 680 35
    296 2 20705 680 35
    261 2 20698 680 35
    267 2 20698 680 35
    277 2 20698 680 35
    293 2 20705 680 35
    408 2 20726 680 35
    324 2 20712 680 35
    393 2 20726 680 35
    263 2 20698 680 35
    260 2 20698 680 35
    278 2 20698 680 35
    340 2 20712 680 35
    325 2 20712 680 35
    316 2 20705 680 35
    351 2 20712 680 35
    391 2 20726 680 35
    317 2 20705 680 35
    369 2 20719 680 35
    318 2 20705 680 35
    271 3 20698 680  4
    399 3 20726 680  4
    383 3 20719 680  4
    395 3 20726 680  4
    365 4 20719 680  8
    379 4 20719 680  8
    306 4 20705 680  8
    404 4 20726 680  8
    378 4 20719 680  8
    280 4 20698 680  8
    376 4 20719 680  8
    374 4 20719 680  8
    392 5 20726 680  1
    141 1 20915 687 34
    175 1 20922 687 34
    131 1 20915 687 34
    133 1 20915 687 34
    246 1 20936 687 34
    218 1 20929 687 34
    188 1 20922 687 34
    244 1 20936 687 34
    258 1 20936 687 34
    242 1 20936 687 34
    134 1 20915 687 34
    139 1 20915 687 34
    248 1 20936 687 34
    204 1 20929 687 34
    216 1 20929 687 34
    185 1 20922 687 34
    206 1 20929 687 34
    198 1 20929 687 34
    137 1 20915 687 34
    250 1 20936 687 34
    136 1 20915 687 34
    190 1 20922 687 34
    135 1 20915 687 34
    167 1 20922 687 34
    172 1 20922 687 34
    217 1 20929 687 34
    177 1 20922 687 34
    129 1 20915 687 34
    150 1 20915 687 34
    138 1 20915 687 34
    184 1 20922 687 34
    247 1 20936 687 34
    168 1 20922 687 34
    214 1 20929 687 34
    163 2 20915 687 14
    199 2 20929 687 14
    182 2 20922 687 14
    233 2 20936 687 14
    153 2 20915 687 14
    125 2 20915 687 14
    161 2 20915 687 14
    197 2 20929 687 14
    213 2 20929 687 14
    236 2 20936 687 14
    257 2 20936 687 14
    189 2 20922 687 14
    170 2 20922 687 14
    205 2 20929 687 14
    249 3 20936 687  5
    162 3 20915 687  5
    237 3 20936 687  5
    240 3 20936 687  5
    140 3 20915 687  5
    241 4 20936 687 15
    234 4 20936 687 15
    201 4 20929 687 15
    149 4 20915 687 15
    187 4 20922 687 15
    238 4 20936 687 15
    158 4 20915 687 15
    229 4 20936 687 15
    179 4 20922 687 15
    252 4 20936 687 15
    200 4 20929 687 15
    183 4 20922 687 15
    243 4 20936 687 15
    147 4 20915 687 15
    144 4 20915 687 15
    245 5 20936 687  4
    160 5 20915 687  4
    148 5 20915 687  4
    164 5 20915 687  4
    473 1 21076 692 29
    449 1 21069 692 29
    493 1 21076 692 29
    427 1 21069 692 29
    460 1 21069 692 29
    513 1 21083 692 29
    437 1 21069 692 29
    530 1 21090 692 29
    545 1 21090 692 29
    482 1 21076 692 29
    546 1 21090 692 29
    448 1 21069 692 29
    516 1 21083 692 29
    514 1 21083 692 29
    536 1 21090 692 29
    547 1 21090 692 29
    481 1 21076 692 29
    535 1 21090 692 29
    531 1 21090 692 29
    471 1 21076 692 29
    466 1 21069 692 29
    452 1 21069 692 29
    458 1 21069 692 29
    446 1 21069 692 29
    483 1 21076 692 29
    423 1 21069 692 29
    475 1 21076 692 29
    544 1 21090 692 29
    426 1 21069 692 29
    424 2 21069 692  6
    476 2 21076 692  6
    541 2 21090 692  6
    440 2 21069 692  6
    533 2 21090 692  6
    539 2 21090 692  6
    478 3 21076 692  3
    447 3 21069 692  3
    445 3 21069 692  3
    474 4 21076 692 11
    484 4 21076 692 11
    500 4 21076 692 11
    442 4 21069 692 11
    465 4 21069 692 11
    517 4 21083 692 11
    429 4 21069 692 11
    518 4 21083 692 11
    453 4 21069 692 11
    456 4 21069 692 11
    461 4 21069 692 11
    511 5 21083 692  4
    534 5 21090 692  4
    527 5 21083 692  4
    464 5 21069 692  4
    end
    
    format dadis %tdDDmonCCYY
    format mydi %tmmonCCYY
    label values ty tyla
    label def tyla 1 "Electronic", modify
    label def tyla 2 "Paper proforma", modify
    label def tyla 3 "Paper letter", modify
    label def tyla 4 "Internal", modify
    label def tyla 5 "NeurosorUnk", modify



    Code:
    * Twoway connected graph
        twoway connected vol mydi if ty==1, sort msize(zero) mcolor(navy) lcolor(navy) lwidth(medthick) ||  ///
            connected vol mydi if ty==2, sort msize(zero) mcolor(dkorange) lcolor(dkorange) lwidth(medthick) lpattern(longdash) ||  ///
            connected vol mydi if ty==3, sort msize(zero) mcolor(dkorange) lcolor(dkorange) lwidth(medthick) lpattern(shortdash_dot) ||  ///
            connected vol mydi if ty==4, sort msize(zero) mcolor(dkgreen) lcolor(dkgreen) lwidth(medthick) lpattern(dot)  ///
            ylabel(0(10)40, labsize(6) angle(zero))  ///
            tlabel(, labsize(6) )  ///
            xtitle("Month-Year", margin(medium) size(6))  ///
            ytitle("Number of referrals", size(6) margin(medium) )  ///
            title("Number of referrals per month and year", c(black) size(6) margin(small) )  ///
            ylabel(, labsize(6) nogrid)  ///
            ysize(3) xsize(8)  ///
            graphregion(fcolor(white) lcolor(white) margin(medlarge))  ///
            plotregion(fcolor(white) lcolor(white) margin(medlarge))  ///
            legend(size(6) order (1 "Electronic" 2 "Paper proforma" 3 "Paper letter" 4 "Internal")  ///
            symxsize(9) symysize(3) margin(small) col(1) pos(3) region(lcolor(white)) span)
    Last edited by Rocio Fernandez Mendez; 09 Jan 2020, 05:51.

  • #2
    mofd() is a function, not a command.

    More interestingly, thanks for your clear data example and your code. There isn't really a problem. The issue is shown by this simplified small variant of your code.


    Code:
    * Twoway connected graph
        twoway connected vol mydi if ty==1, sort mcolor(navy) lcolor(navy) lwidth(medthick) ||  ///
            connected vol mydi if ty==2, sort mcolor(dkorange) lcolor(dkorange) lwidth(medthick) lpattern(longdash) ||  ///
            connected vol mydi if ty==3, sort mcolor(dkorange) lcolor(dkorange) lwidth(medthick) lpattern(shortdash_dot) ||  ///
            connected vol mydi if ty==4, sort mcolor(dkgreen) lcolor(dkgreen) lwidth(medthick) lpattern(dot)  scheme(s1color)

    Click image for larger version

Name:	notaproblem.png .png
Views:	1
Size:	33.9 KB
ID:	1531351


    As explicit marker symbols show, the September values are plotted where they should be. Nothing has been mangled.


    You are letting twoway decide where to put the axis labels and -- having looked at your data and your display formats -- it decided to show each April (month 4) and October (month 10) as labels. They are 6 months apart, a congenial and natural spacing for monthly data. twoway does not feel compelled to put a label at each data point or to notice irregular spacing. This command shows you the positions you should feed to twoway, xla() to override its default.



    Code:
    . levelsof mydi
    675 680 687 692

    Comment


    • #3
      Many thanks for clarifying Nick

      Comment

      Working...
      X