Announcement

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

  • Correlation between two variables but use a third variable for sorting

    Hi all, I am new to STATA and I would like to correlate two variables taking YEAR as the sorting variable.

    YEAR VAR1 VAR2
    2005 1 1
    2006 3 3
    2007 2 5

    What I am after is to find how does VAR2 changes when VAR1 is decreased. I am thinking of finding the slope between each two consecutive years but I don't know how to proceed afterwards.

    Thank you


  • #2
    It certainly sounds like you do not have a clear understanding of basic statistics. Your description is quite unclear.

    If you just want to look at the correlations, you use the corr or pwcorr command.

    However, if you are only looking for changes in VAR2 when VAR1 decreases between years or the slope between two consecutive years, then you have two different problems. That is,you're describing three different things as if they were the same.

    If you only have one time series (i.e., we don't have to worry about multiple panels), then you can attack the third question one of two ways. You could tsset the data (in which case Stata knows YEAR is the time variable) and then you can refer to the previous year's value using the lag (L.) operator. Thus, you might generate a variable that includes the fractional change in var two by:
    gen diff=(VAR2 - L.VAR2)/L.VAR2

    Or, if you don't want to tsset the data, you can refer to the previous observation (assuming that it is the previous year) by:
    gen diff=(VAR2 - VAR2[_n-1])/VAR2[_n-1]

    I hope this helps. It sounds like you either haven't tried to really solve the problem or don't have the basic statistical background for the package. Spend some time on this before asking any questions. Also, read the FAQ and guidelines for this listserve. We use our real names among other things.

    Comment


    • #3
      It certainly sounds like you do not have a clear understanding of basic statistics. Your description is quite unclear.

      If you just want to look at the correlations, you use the corr or pwcorr command.

      However, if you are only looking for changes in VAR2 when VAR1 decreases between years or the slope between two consecutive years, then you have two different problems. That is,you're describing three different things as if they were the same.

      If you only have one time series (i.e., we don't have to worry about multiple panels), then you can attack the third question one of two ways. You could tsset the data (in which case Stata knows YEAR is the time variable) and then you can refer to the previous year's value using the lag (L.) operator. Thus, you might generate a variable that includes the fractional change in var two by:
      gen diff=(VAR2 - L.VAR2)/L.VAR2

      Or, if you don't want to tsset the data, you can refer to the previous observation (assuming that it is the previous year) by:
      gen diff=(VAR2 - VAR2[_n-1])/VAR2[_n-1]

      I hope this helps. It sounds like you either haven't tried to really solve the problem or don't have the basic statistical background for the package. Spend some time on this before asking any questions. Also, read the FAQ and guidelines for this listserve. We use our real names among other things.

      Comment


      • #4
        I think you just need to use this command: correlate VAR1 VAR2

        Comment

        Working...
        X