Announcement

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

  • Scaling a variable by another variable

    Hi everyone,

    I need to calculate a variable as the standard deviation of another variable scaled by yet another variable, requiring at least 3 years of data.
    This is how I calculate the standard deviation:

    egen cfv = sd(oibdp)

    But then I don't know how to proceed to scale the variable as explained above. Can anyone help me?

    Thank you in advance!

  • #2
    What you want isn't clear to me.


    Code:
    egen cfv = sd(oibdp)
    uses all available data for one variable and calculates a single standard deviation which goes in a new variable, each observation holding the same value.

    Nothing there is said about years of available data.

    I think you need to tell us much more about your data. https://www.statalist.org/forums/help#stata is key.

    Comment


    • #3
      Sorry about my unclear post.

      I am using the Compustat data set, where I need to calculate the Cash flow volatility. It is said to be the standard deviation of historical operating income, scaled by total assets, requiring at least 3 years of data.
      Here an example of what my data looks like:

      gvkey fyear at oibdp
      1000 1970 33.45 5.386
      1000 1971 29.33 2.512
      1000 1972 19.907 4.109
      1000 1973 21.771 4.514
      1000 1974 25.638 4.82
      1000 1975 23.905 6.364
      1000 1976 38.586 8.741
      1000 1977 44.025 6.01
      1001 1983 14.08 2.65
      1001 1984 16.267 3.208
      1001 1985 39.495 7.247
      1002 1970 13.722 1.84
      1002 1971 12.123 2.009
      1002 1972 15.676 1.968
      1003 1983 8.529 2.138
      1003 1984 8.241 .825
      1003 1986 14.586 2.462
      1003 1987 16.042 .111
      1003 1988 16.28 -3.68
      1003 1989 10.109 -1.532
      1004 1967 4.88 .201
      1004 1968 10.402 .999
      1004 1969 11.584 1.149
      1004 1970 13.468 1.574
      1004 1971 16.501 2.207
      1004 1972 24.068 3.376
      1004 1973 31.584 5.075
      1004 1974 43.353 4.785
      1004 1975 43.539 4.958
      1004 1976 45.55 5.538
      1004 1977 56.502 6.74
      1004 1978 64.194 10.037
      1004 1979 73.758 10.556
      1004 1980 83.075 11.058
      1004 1988 356.391 51.051
      1004 1989 388.521 54.032

      with gvkey : firm id, fyear: time id, at: total assets, oidp: operating income before depreciation.

      Is it more clear like this?

      Comment


      • #4
        I guess that helps someone. I don't work in your field but I imagine that lumping together different gvkey makes no sense. Beyond that the questions you need to answer for others to help you might well include

        sd(operating income)/assets OR sd(operating income/assets)?

        in 3 year moving windows?

        Comment


        • #5
          I suggest following the FAQ on asking questions. For example, using dataex to generate your data will help us use your data.

          I think I understand what you are trying to do. You want the 3 year standard deviation in operating income by firm year. I assume this is the current and two previous years.

          Code:
          xtset  gvkey fyear
          
          g Lat=L.at
          g L2at=L2.at
          
          egen std1=rowsd(at Lat L2at) if Lat<. & L2at<.
          g byat=std1/at
          I suspect there is a more efficient way to do this with rangestat or something, but this works. You have to choose whether it is current and previous two years or previous 3 years and what to do for the second observation for each firm (where you only have 2 years of data - I've set it to missing if you if you don't have both lagged variables.

          As Nick notes, there is also the possibility that you want to normalize income before doing the std, but that is so easy to program, you should be able to do it.

          Comment

          Working...
          X