Announcement

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

  • having issues plotting stock returns in panel data

    Dear statalist, i am trying to plot the stock return data for a panel data of some companies, however, each time i plot this, but each time i plot this using xtline command, i get an vertical line which does not show any dynamics in the variable movement. however, if i plot the closing price of the stock, the plot looks good.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(Date ret4) str6 ticker long bcal_date
    22280          . "ABF.L"  0
    22284 -1.6926985 "ABF.L"  1
    22285 -1.0840229 "ABF.L"  2
    22286   2.688337 "ABF.L"  3
    22287 -1.4247924 "ABF.L"  4
    22288 -.49449205 "ABF.L"  5
    22291  .04506954 "ABF.L"  6
    22292    .045015 "ABF.L"  7
    22293          0 "ABF.L"  8
    22294   1.519262 "ABF.L"  9
    22295 -.26643598 "ABF.L" 10
    22298   .9294199 "ABF.L" 11
    22299  -.1763671 "ABF.L" 12
    22300  1.6630546 "ABF.L" 13
    22301   .6489297 "ABF.L" 14
    22302  -2.842971 "ABF.L" 15
    22305  -2.424892 "ABF.L" 16
    22306  .09086218 "ABF.L" 17
    22307  -.7750133 "ABF.L" 18
    22308  .18288766 "ABF.L" 19
    22309  -3.344475 "ABF.L" 20
    22312   3.891174 "ABF.L" 21
    22313  1.6670744 "ABF.L" 22
    22314   .4013417 "ABF.L" 23
    22315   .8420265 "ABF.L" 24
    22316  1.0535668 "ABF.L" 25
    22319 -1.0977212 "ABF.L" 26
    22320   .3085941 "ABF.L" 27
    22321 -1.4184653 "ABF.L" 28
    22322  -.4474456 "ABF.L" 29
    22323 -.13461708 "ABF.L" 30
    22326   5.290861 "ABF.L" 31
    22327 -1.7615863 "ABF.L" 32
    22328   .0433178 "ABF.L" 33
    22329   .5185954 "ABF.L" 34
    22330  2.1744623 "ABF.L" 35
    22333   1.506937 "ABF.L" 36
    22334  1.9338083 "ABF.L" 37
    22335  -.6951607 "ABF.L" 38
    22336  -.6587002 "ABF.L" 39
    22337  -2.213491 "ABF.L" 40
    22340  1.2172174 "ABF.L" 41
    22341 -1.2594588 "ABF.L" 42
    22342   .6736876 "ABF.L" 43
    22343 -.04197542 "ABF.L" 44
    22344 -1.0975165 "ABF.L" 45
    22347  .25434014 "ABF.L" 46
    22348  2.0947537 "ABF.L" 47
    22349  -.7072873 "ABF.L" 48
    22350  -.5023145 "ABF.L" 49
    22351   1.664616 "ABF.L" 50
    22354  1.3527613 "ABF.L" 51
    22355   1.535391 "ABF.L" 52
    22356 -1.3320118 "ABF.L" 53
    22357 -1.8454542 "ABF.L" 54
    22358 -.08282112 "ABF.L" 55
    22361    -.74844 "ABF.L" 56
    22362 -2.3649566 "ABF.L" 57
    22363   -.428283 "ABF.L" 58
    22364     .12867 "ABF.L" 59
    22365  2.5810676 "ABF.L" 60
    22368  -.7126455 "ABF.L" 61
    22369  1.8341514 "ABF.L" 62
    22370 -.24813415 "ABF.L" 63
    22371  1.4796733 "ABF.L" 64
    22376   .4884022 "ABF.L" 65
    22377   .7684655 "ABF.L" 66
    22378   .3217926 "ABF.L" 67
    22379  -.2412499 "ABF.L" 68
    22382  -.8490082 "ABF.L" 69
    22383 -.20321368 "ABF.L" 70
    22384  -.6530541 "ABF.L" 71
    22385   .6937422 "ABF.L" 72
    22386  -1.268688 "ABF.L" 73
    22389   1.309339 "ABF.L" 74
    22390  -6.118375 "ABF.L" 75
    22391 -.25963387 "ABF.L" 76
    22392  .21640652 "ABF.L" 77
    22393  -.8248349 "ABF.L" 78
    22396   .9976213 "ABF.L" 79
    22397  -.6060578 "ABF.L" 80
    22398 -.17382672 "ABF.L" 81
    22399   .9092869 "ABF.L" 82
    22400  -.5185954 "ABF.L" 83
    22404  -.7829376 "ABF.L" 84
    22405   .8695608 "ABF.L" 85
    22406  1.2903584 "ABF.L" 86
    22407   .4264242 "ABF.L" 87
    22410   .8052581 "ABF.L" 88
    22411 -3.3916016 "ABF.L" 89
    22412  -.4376436 "ABF.L" 90
    22413 -1.8592914 "ABF.L" 91
    22414  2.7326605 "ABF.L" 92
    22417 -1.0050433 "ABF.L" 93
    22418     .43823 "ABF.L" 94
    22419 -1.0549673 "ABF.L" 95
    22420   2.616812 "ABF.L" 96
    22421 -.56119645 "ABF.L" 97
    22424   .8620755 "ABF.L" 98
    22425 -1.7316363 "ABF.L" 99
    end
    format %td Date
    format %tbcalendar bcal_date

  • #2
    The graph I got looks like this, I guess it might be a scaling issue.
    Attached Files

    Comment


    • #3
      That's not a vertical line. The variable plotted is just going up and down like a yo-yo over a short fraction of the entire data record. Look for values of ret4 over say 100 in absolute value.


      Code:
      list if abs(ret4) > 100 & ret4 < .

      Comment


      • #4
        The ret4 variable is multiplied by 100, so I only get 9 observations, I created another variable called ret without multiplying by 100 . So the graph looks the same as that of ret4, . When I tried to get the summary stat, the minimum for ret ranges between -4.63 and 4.62 . Although the values I'm seeing in the data browser is different from what Stata is saying about the minimum and maximum values.

        Here's the command I used to calculate the daily returns

        Bys ticker (Date): gen ret= ln(Adjclose/Adjclose [_n-1])


        Bys ticker (Date) gen ret4= 100*(log(Adjclose [_n]) - log(Adjclose [_n-1])

        Comment


        • #5
          This is hard to follow. All the ret4 values shown in #1 are close to 0. But if the graph in #2 is based on multiplying by 100, why are you surprised at seeing some values of the order of 100?

          Also, your graph is based on a business calendar date but your calculations are based on a standard date. That is probably not an issue. but I mention it.

          Comment


          • #6
            So what could be the probable problem why the data show's Small values while the graph is showing values above 100.plotting the original adjusted closing price shows the dynamics. Even when the return is calculated based on business calendar, its still same graph that shows up

            Comment


            • #7
              In #3 I suggested looking at the data using list

              Comment


              • #8
                B
                I was able to generate this after generating the mean of the return series across the panel. This is a bit better. However, I will like to generate similar graph for my two sectors tourism=1 and agric=0. It seems the is an abnormal return during the period before august as shown in the graph. Is it also possible to have the date closer to each other so I can get to know the exact date of this occurrence..
                Attached Files
                Last edited by Hamid muili; 30 Dec 2022, 19:59.

                Comment


                • #9
                  Nick Cox , is it possible to reduce the axis scaling of my graph to look like the attached graph
                  Attached Files

                  Comment


                  • #10
                    You should use an if condition to restrict the time range.

                    Comment


                    • #11
                      Nick Cox , thanks pls can you give a short example of how to do that.
                      Secondly, the date on the y Axis is too wide (5 months), how do I reduce this to 2 months interval.

                      Comment


                      • #12
                        There is an example within

                        Code:
                        help axis scale options

                        Comment

                        Working...
                        X