Announcement

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

  • Graphs for panel data

    How can I represent these kind of information in a graph?

    Code:
    year  GDP1    GDP2    GDP3   GDP4  GDP5    GDP6   GDP7    GDP8   GDP9
    2000    -1.541017            13.9542    .0433187        7.404528    -12.99462    291.8457
    2001    .3180057            -11.97015    .0960759        -20.4245    2.980698    114.1066
    2002    .4563906            -35.96729    -.636384        5.535862    10.88125    181.8915
    2003    8.265878            -8.398011    -.1266499        7.20142    -25.72067    179.6897
    2004    2.041637                .0521964        -.2348184    -41.20754    118.9573
    2005    3.464516                -.3475167        5.177906    -50.41868    15.43606
    2006    -.7168548                1.858704        1.084828    -42.72681    -3.513266
    2007    -24.56103                -.1940463        .0013032    -45.06967    17.1728
    2008    27.65182                -4.747163        -.429086    -56.69781    5.724859
    2009    16.65592        -30.40432        -4.134741        .0469369    -65.31234    10.3612
    2010    26.01829                -.7762281        -.1593683    -57.49863    -.3161917
    2011    -33.2877                1.345968            -53.86568    17.71495
    2012    -25.12523                6.111485    40.26471        -53.94812    9.130902
    2013    12.40837                8.403982        -.2203234    -39.73179    24.69587
    2014    14.28746                -.6371735            -33.13484    25.74029

    I want to show how the GDP for different countries(1, 2, ...9 represent countries) varies over the years.


    PS. Apologies I do not have data example as required in FAQ 12...

  • #2
    These look utterly implausible as GDPs even as logarithms or rates of change.

    Comment


    • #3
      They are inaccuracies in measurement of GDP (computed as difference between GDP values from 2 sources)

      Comment


      • #4
        I see; thanks for the clarification.

        Next problem then: Your example implies 9 GDP variables, but I see even on a first glance 4, 5, 6 in various observations. Presumably the gaps imply missings, but this is not up to scratch as an example for us to work with.

        Please do follow FAQ Advice and show the results of

        Code:
        ssc inst dataex 
        dataex GDP? year

        Comment


        • #5
          Code:
          input int year float(bvare ethvare kevaree mdgvare)
          2000  16.721798  .06789716     10.36884 -17.134523
          2001  -8.630292   7.607203    27.829233 -16.708027
          2002  13.739996   8.307977     51.12066  -22.09546
          2003  -42.83727   1.399222    -5.482161 -34.210495
          2004  -43.28529 .024332473    .02895465  -41.44461
          2005  -16.64176 .022148257    -3.707865  -50.52535
          2006  -74.46115  .12611267   -1.8484677  -43.00698
          2007  -60.42108   .3632965   -.02285513  -44.02803
          2008  -61.86467 -2.5694025    -.5191518  -56.54366
          2009  -45.07589  -5.963307 -.0004403103 -65.337975
          2010 -14.975846  -2.582902    -.3891703  -57.50819
          2011  -38.38507   40.37641            .  -52.47515
          2012  -45.62659   40.47289            .  -50.27428
          2013  -51.78159  -23.38525     5.758736  -39.05609
          2014 -12.585526  -42.51928            . -34.163967

          Comment


          • #6
            Thanks; that works. You can try things like

            Code:
            tsset year 
            tsline *var*
            Click image for larger version

Name:	tslinethisone.png
Views:	1
Size:	10.7 KB
ID:	1361643


            This can be tuned, naturally. I haven't worked at it because help tsline documents how to do it.

            Otherwise this graph below is a result of something I am working on intermittently

            Click image for larger version

Name:	multiline.png
Views:	1
Size:	30.1 KB
ID:	1361644


            Code:
            multiline *var* y, xla(2000(2)2014) xtitle("") recast(connected)
            where multiline is defined by

            Code:
            *! 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) *] 
                    
                    quietly { 
                            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' 
                            }
            
                            tempname y 
                            stack `call', into(`y' `panelvar' `xvar') clear 
            
                            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''"'
            
                    line `y' `xvar', by(_stack, col(1) yrescale note("") `by') ///
                    ytitle("") yla(, ang(h)) c(L) ///
                    subtitle(, pos(9) bcolor(none) nobexpand place(e)) `options' 
            end
            and there is as yet no help file.

            Comment


            • #7
              I've tried the second syntax but I get the error message: invalid syntax

              This is the syntax i used after running the multiline code.

              Code:
               
               multiline *bvare ethvare kevaree mdgvaree* y, xla(2000(2)2014) xtitle("") recast(connected)

              Comment


              • #8
                According to your example
                Code:
                 
                 bvare ethvare kevaree mdgvare
                are the names of the variables and if that's so it could be that you have no variables
                Code:
                 
                 mdgvaree*

                Comment


                • #9
                  What do you mean by I have no variables?
                  What you​​​​'ve listed are my variables which i generated by taking the difference between the values from the 2 data sources

                  Comment


                  • #10
                    The spelling of the variables mdgvaree* does not include mdgvare : there is no sense in which that first varlist includes that last variable as a member. The extra e rules that out.

                    My code in #6 works with the example you gave in #5: otherwise the graph would not have been possible.

                    I have no idea why you changed the syntax, but if you do your syntax must be compatible with your variable names.

                    Another possibility is that you didn't copy and paste the code correctly. What does

                    Code:
                    which multiline
                    tell you?

                    Comment


                    • #11
                      Code:
                      command multiline not found as either built-in or ado-file
                      Is the message i get when i type
                      Code:
                      which multiline

                      Comment


                      • #12
                        You haven't installed it then. The code, so far as you are concerned, is only in #6 here and will not work remotely until and unless you put it in a file multiline.ado along your adopath. I can't put it on your computer for you (and wouldn't even if I could).

                        Comment


                        • #13
                          I ran the code provided in #6 and I have run it again but I still get the same error message and when I run
                          Code:
                          which multiline
                          I still get
                          Code:
                          command multiline not found as either built-in or ado-file

                          Comment


                          • #14
                            Sorry, same answer as in #12 without more information. Your adopath is given by typing as a command


                            Code:
                            adopath
                            The adopath shows where Stata will look for program files.

                            When I do that on my computer, part of what I get (I am not showing you everything) is

                            Code:
                            . adopath
                              [5]  (PLUS)      "d:/njc/ado/plus/"
                            when I do

                            Code:
                            which multiline
                            I get this


                            Code:
                            . which multiline
                            d:/njc/ado/plus\m\multiline.ado
                            *! 1.1.0 NJC 2oct2016
                            In other words, Stata can see the program multiline in a file of the same name but with .ado extension multiline.ado because, and only because, I created that file with a text editor and put the code in it. And that file is on my adopath. It is just off (Americans say "off of") the adopath but that's OK, as if foo is on the adopath then foo\m will be searched too if Stata is looking for a file whose name begins with "m" (or foo/m depending on operating system), and similarly for any other letter a ... z or underscore as first character in a program name.

                            I do realise that this is more complicated for non-programmers who at most install user-written programs using ssc or net but I mention my program that way because it remains under development yet does graphs not otherwise easy to do.

                            Comment


                            • #15
                              Sorry for being so slow, I am a novice in stata.

                              Now when I do
                              Code:
                              whichmultiline
                              I get
                              Code:
                              .\multiline.ado
                              *! 1.1.0 NJC 2oct2016

                              But when I run:
                              Code:
                               multiline bvare kevaree ethvaree mdgvare y, xla(2000(2)2014) xtitle("") recast(connected)
                              I still get:
                              Code:
                              invalid syntax
                              What could be the problem?

                              Comment

                              Working...
                              X