Announcement

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

  • #16
    Indeed. I edited the help file recently and spotted that I had updated the code not so long ago but not uploaded the latest version to SSC.

    Comment


    • #17
      Does this command support datelists in axis labeling?
      I'm using Stata/MP 17

      Comment


      • #18
        It supports varying date-time formats in the standard way, e.g.

        .
        Code:
         webuse grunfeld, clear
        
        . multiline invest mvalue kstock year if company == 1
        
        . multiline invest mvalue kstock year if company == 1, xla(, format(%tyYY))
        Otherwise do try what you want to find out.

        Comment


        • #19
          Nick Cox , as seen in the graph, does if company==1 representing just company 1 or it's for the entire company.
          Another question is, can I use this graph for sub-group graph. like company 1,2,4,5, (high financial leverage) company 3,6,7,8(low financial leverage). Something like that.

          Comment


          • #20
            does if company==1 representing just company 1 or it's for the entire company.
            if company == 1 selects observations for company 1 and no others. I am not sure what the entire company means here. If you mean "the entire set of companies", no

            can I use this graph for sub-group graph. like company 1,2,4,5, (high financial leverage) company 3,6,7,8(low financial leverage). Something like that
            That sounds like a different graph of some kind.

            Comment


            • #21
              Dear Nick,

              I would like to ask another thing about the multiline command. I actually using a panel dataset for 133 countries for the period 1995-2011 and I was representing the trend of two variables, namely eci and ecirank, for some specific countries I am interested in. I was trying to exhibit the values for these respective two varibles in my graph by using the option mlabel but when I try to proceed in this way, Stata gives me the following error:

              multiline eci ecirank year if country == "Argentina", recast(connected) xline(2015, lcol(red)) xlabel(1995(5)2020) mlab(eci)

              variable eci not found
              r(111);

              However, this variable is clearly included in my dataset, in fact, when I reproduce the graph with the multiline command without mlab option I obtain the following representation:

              Graph Argentina.gph

              Comment


              • #22
                Iacopo Taddei

                ​​​​​​​What happens is that multiline works with a different version of your data, stacked so that the graph command can call up a by() option. Within that dataset, your original variables are no longer visible under their original names, so the mla() option can't see the variable you specify.

                You could try this hacked version, in which the intent is that variables you need to use are copied along. You need the extra option need(eci) in your call to multiline.

                I haven't tested the code, but if it doesn't work please tell me and I will get to this (much) later today.


                Code:
                *! 1.6.1 NJC 6nov2023
                *! 1.6.0 NJC 27mar2022
                * 1.5.0 NJC 13jul2020
                * 1.4.1 NJC 5apr2020
                * 1.4.0 NJC 14mar2019
                * 1.3.1 NJC 14jul2017
                * 1.3.0 NJC 3jul2017
                * 1.2.0 NJC 8mar2017
                * 1.1.0 NJC 2oct2016
                * 1.0.0 NJC 5sept2016
                program multiline
                    version 11
                    syntax varlist(numeric) [if] [in] ///
                    [, by(str asis) mylabels(str asis) MISSing SEParate SEPby(varname) savedata(str asis) SHOW(varname) addplot(str asis) need(str asis) *]
                    
                    // undocumented show() addplot()
                
                    quietly {
                        if "`sepby'" != "" {
                            if "`separate'" != "" {
                                di as err "separate and sepby() options cannot be combined"
                                exit 198
                            }
                        }
                            
                        if "`missing'" != "" marksample touse, novarlist
                        else marksample touse
                
                        count if `touse'
                        if r(N) == 0 exit 2000
                
                        preserve
                        keep if `touse'
                        drop `touse'
                    
                        gettoken yvar rest : varlist
                        local J = 0
                        while "`yvar'" != "" {
                            local ++J
                            local lbl`J' : var label `yvar'
                            if `"`lbl`J''"' == "" local lbl`J' "`yvar'"
                            local last "`yvar'"
                            gettoken yvar rest : rest    
                        }
                
                        local xvar "`last'"
                        local yvar : list varlist - xvar
                
                        capture tsset
                        if "`r(panelvar)'" != "" local panelvar "`r(panelvar)'"
                
                        foreach v of local yvar {
                            local call `call' `v' `panelvar' `xvar' `show' `sepby' `need'
                        }
                
                        tempname y
                        tempfile myxvar
                        local label : value label `xvar'  
                        label save `label' using "`myxvar'"
                
                        if "`panelvar'" != "" {
                            local label2 : value label `panelvar'
                            if "`label2'" != "" {
                                tempfile mypanelvar
                                label save `label2' using "`mypanelvar'"
                                local flag1 = 1
                            }
                        }    
                
                        if "`sepby'" != "" {
                            local label3 : value label `sepby'
                            if "`label3'" != "" {
                                tempfile mysepby
                                label save `label3' using "`mysepby'"
                            }
                        }
                
                        stack `call', into(`y' `panelvar' `xvar' `show' `sepby' `need') clear
                 
                        do "`myxvar'"
                        if "`label'" != "" {
                            label val `xvar' `label'
                        }
                
                        if "`label2'" != "" {
                            do "`mypanelvar'"
                            label val `panelvar' `label2'
                        }
                
                        if "`label3'" != "" {
                            do "`mysepby'"
                            label val `sepby' `label3'
                        }
                
                        local Jm1 = `J' - 1
                        if `"`mylabels'"' != "" {
                            tokenize `mylabels'
                            forval j = 1/`Jm1' {
                                label def _stack `j' `"``j''"', add
                            }
                        }
                        else forval j = 1/`Jm1' {
                            label def _stack `j' `"`lbl`j''"', add
                        }
                        label val _stack _stack
                    }
                
                    sort `panelvar' `xvar'
                    label var `xvar'  `"`lbl`J''"'
                
                    if `"`by'"' == "" local by "cols(1)"  
                    else {
                        local found 0
                        foreach opt in c co col cols {
                            if strpos(`"`by'"', "`opt'(") {
                                local found 1
                                continue, break
                            }
                        }
                        if !`found' local by `"`by' cols(1)"'
                    }  
                
                    local Y `y'
                
                    quietly {
                        if "`separate'" != "" {
                            separate `y', by(_stack) veryshortlabel
                            local y `r(varlist)'
                        }
                        else if "`sepby'" != "" {
                            separate `y', by(`sepby') veryshortlabel
                            local y `r(varlist)'
                        }
                    }  
                        
                    if "`show'" != "" local show mla(`show') mlabpos(3)
                
                    line `y' `xvar', by(_stack, yrescale note("") `by') ///
                    ytitle("") yla(, ang(h)) c(L) ///
                    subtitle(, pos(9) bcolor(none) nobexpand place(e)) `show' `options' ///
                    || `addplot'
                
                
                    if `"`savedata'"' != "" {
                        capture rename `Y' _y
                        save `savedata'
                    }
                end

                Comment

                Working...
                X