Announcement

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

  • cmissing(n) in twoway line plot not working

    Hello,

    I think I'm being a little dumb here. If you load the attached file and run the following code:

    Code:
    clear
    
    cd " "
    use irdata
    
    tsset DATE_MONTH
    
    twoway (line I_NFC I_MORT I_OTH DATE_MONTH , cmissing(n)) /*
            */ (line I_CONS DATE_MONTH, yaxis(2) cmissing(n)) /*
            */ , xline(657) xtitle("") ytitle("", axis(2)) yscale(range(4.8 8.2) axis(2)) yscale(range(.8 4.2)) ylabel(5(1)8, axis(2))
    ... then the third and eigth observation of I_MORT should not be connected, right? But when I run it, they always are. What am I doing wrong?


    Running the following example I've found on the internet works just fine, but I can't find the difference to my data or code.

    Code:
    clear
    set obs 60
    
    //Generating date variable
    local i = 0
    local cmd generate
    forvalues month = 1/12{
        forvalues year = 2011(1)2015{
            `cmd' datestr = "1/`month'/`year'" in `=`++i''
            local cmd replace
        }
    }
    generate date = date(datestr, "DMY")
    format date %d
    
    //Sorting on date
    sort date
    
    //Generating 'ratio' variable
    gen Ratio = rbeta(3,0.5)
    
    //Making some observations missing
    forvalues i = 1(9)60{
        replace date = . in `i'
    }
    
    //Generating a treatment indicator
    gen treated = mod(_n,2)
    
    //Plotting
    twoway (line Ratio date if treated==1, cmissing(n)) (line Ratio date if treated==0, cmissing(n))
    
    
    , ///
            ysc(r(0 1)) ylab(0(0.2)1, format(%9.1f)) xtitle("") xlab(, format(%tddd/nn/YY)) ///
            legend(pos(6) ring(1) col(2) lab(1 "Treatment") lab(2 "Control") size(3) region(c(none)))
    Attached Files

  • #2
    You have multiple plots, for one. See

    Code:
    help stylelists

    Comment


    • #3
      Please use dataex not ,dta attachments. This is explained at https://www.statalist.org/forums/help#stata


      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float DATE_MONTH double(I_MORT I_CONS I_OTH I_NFC)
      612 3.69 7.22 3.21 2.77
      613  3.9 7.27 3.38    3
      614 3.97 7.44  3.5    3
      615    . 7.24 3.58 3.19
      616    . 7.38 3.75  3.2
      617    . 7.32  3.7 3.29
      618    . 7.42 3.65 3.27
      619 3.97 7.38 3.74 3.29
      620 3.73 7.53 3.61  3.2
      621 3.56 7.57 3.48 3.29
      622 3.53    7 3.52 3.16
      623 3.49 6.57 3.39 3.17
      624 3.46 7.25 3.19 2.88
      625 3.39 7.17  3.1 2.83
      626 3.27 6.79 3.11 2.71
      627  3.3 6.81 2.97 2.64
      628 3.18 6.82 2.98 2.61
      629 3.03 6.65  2.9 2.62
      630 2.99 7.08 2.71 2.49
      631 2.92 6.84 2.65 2.36
      632 2.86 6.71 2.55 2.34
      633 2.83 6.74 2.43  2.2
      634  2.8 6.54 2.44 2.27
      635 2.79  6.2 2.41 2.19
      636 2.75 6.93 2.53 2.14
      637 2.77 6.83 2.42 2.11
      638 2.78 6.65 2.47 2.15
      639 2.78 6.68 2.54 2.13
      640 2.68 6.77 2.45 2.04
      641 2.62 6.82 2.39 2.08
      642 2.67 6.81 2.51 2.09
      643 2.76 6.66 2.51 2.04
      644 2.83 6.64 2.53 2.14
      645 2.84 6.64  2.4 2.13
      646 2.87 6.53 2.47 2.07
      647  2.8 6.16 2.43 2.19
      648 2.81 6.81 2.45 2.14
      649 2.83 6.69 2.47 2.11
      650 2.72 6.49 2.54 2.26
      651 2.71 6.56 2.46 2.12
      652 2.63 6.76 2.48 2.13
      653 2.55 6.68 2.48 2.04
      654 2.46 6.69 2.35 1.98
      655 2.41 6.49 2.44 1.89
      656  2.3 6.38  2.3 1.91
      657 2.25 6.38 2.18 1.86
      658 2.17 6.28 2.27 1.87
      659 2.13 5.94 2.11 1.87
      660 1.96 6.38  2.2 1.67
      661 1.96 6.42 2.04 1.59
      662 1.88 6.01 2.08 1.73
      663 1.87 6.11 2.03 1.68
      664 1.77 6.24 1.95 1.66
      665 1.85 6.29 1.95 1.71
      666 1.99  6.4 2.08 1.68
      667 2.06 6.26 2.12 1.62
      668 2.03 6.21 2.19 1.84
      669 2.05  6.2 2.07 1.68
      670 2.02 6.15 2.03 1.67
      671 1.95 5.97 2.05 1.68
      672 1.97 6.37 1.96  1.6
      673 1.96  6.2 2.05 1.54
      674 1.82 6.04 2.02 1.64
      675 1.88 6.19 2.03 1.55
      676 1.79  6.2    2 1.47
      677 1.76 6.18 2.02 1.52
      678 1.73 6.18 1.89 1.46
      679 1.68 6.06 2.02 1.43
      680 1.64 5.92 1.89 1.51
      681 1.62 5.93 1.89 1.43
      682 1.62 5.83 1.92 1.45
      683 1.66 5.67 1.93 1.53
      684 1.77 6.04 1.94 1.33
      685 1.81  5.8 1.94 1.33
      686 1.82  5.6 2.01  1.5
      687 1.85 5.65    2 1.43
      688 1.83 5.87 2.02 1.35
      689 1.82 5.88 2.06 1.41
      690 1.82 5.97 1.96 1.39
      691 1.87 5.86 1.99 1.38
      692 1.86 5.65 1.99 1.38
      693 1.85 5.65 2.08 1.35
      694 1.84 5.61 1.98  1.4
      695 1.79 5.37    2 1.43
      696 1.82 5.83 2.01 1.22
      697 1.84 5.68 1.97 1.32
      698 1.89 5.43 2.03 1.42
      699 1.89 5.64 2.12 1.39
      700 1.91 5.85 2.04  1.2
      701  1.9 5.85 2.06 1.31
      702 1.88    6 2.06 1.19
      703 1.87 6.02 2.07 1.18
      704 1.86 5.91 2.08 1.26
      705 1.86 5.99 2.11 1.28
      706 1.88 5.83 1.96 1.27
      707 1.85 5.81 1.89 1.29
      708    .    .    .    .
      end
      format %tm DATE_MONTH

      Extending Andrew Musau's answer: you need to specify cmissing() in respect of each variable it applies to. Your syntax only specifies the first. Consider some variation on

      Code:
      twoway (line I_NFC I_MORT I_OTH DATE_MONTH , cmissing(n ..))

      Comment


      • #4
        Oh shoot, that was a dumb one. ^^

        Thanks for the answers and the hint with dataex. I'll stick to it in the future.

        Comment

        Working...
        X