Announcement

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

  • Standard deviation in panel data set

    Hello,

    I have a Panel Dataset and I am looking to calculate standard deviations of a variable, that is, quarterly inflation, for 53 countries over a period of 1980-2014. Could you tell me how I might be able to perform the same? I need to calculate the standard deviation over two different periods. For example, between 1980 and 1998 and then from 1999 and 2014.

    I have performed the following, however I am not sure how stata calculates it, as upon using it I get one value repeated value for SD for each country. I am using Stata 12 and 13 (both) .

    Code:
     
     bys country : egen SD = sd(inflation)
    Any help would be extremely useful,

    Thank you,
    Mridula

  • #2
    Mridula:
    what if you type:
    Code:
    bysort country year: egen SD=sd(inflation)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      The way I read it is very close but a little different from what Carlo suggests. If you want to use only data in certain periods of years, you will have to tell Stata which are the periods you are interested in. First create a variable that indicates period, then do the calculation of sd simialr to what Carlo suggested, e.g.:
      Code:
      gen period = 1 if Year>=1980 & Year <=1998
      replace period = 2 if Year>=1999 & Year <=2014
      bysort country period: egen SD=sd(inflation)
      Last edited by Jorrit Gosens; 28 Jul 2015, 07:26.

      Comment


      • #4
        Carlo,

        If I use the above code, it creates only missing value for standard deviations.

        Thank you,
        Mridula

        Comment


        • #5
          Jorrit,

          I will try using what you have suggested.

          Thank you,
          Mridula

          Comment


          • #6
            Do you have quarterly or yearly data? With quarterly data Carlo's code should at least also work.

            Comment


            • #7
              I have both quarterly and yearly data. However, at the moment working with yearly data.

              Comment


              • #8
                Well, the code Carlo suggests would calculate sd per country and year. That's possible with quarterly data. With yearly data you're asking Stata to calculate the sd of a single value, producing a missing value.

                Comment


                • #9
                  Right. Thank you so much. Will try this with quarterly data. Hopefully, should work.

                  Comment

                  Working...
                  X