Announcement

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

  • Compute covariance and store in column

    My data are the following:
    I have a dataset with 77000 rows and 3 columns.
    I want to compute the covariance of dclose and dclose_lag for each identifier ticker2.
    So I need 194 covariances.

    How can I create a column consisting of the covariances?

    I have already computed the variance for the first ticker2, but I can not create a loop.

    That is the command i used to compute the covariance for the 1st ticker2:

    correlate dclose dclose_lag if ticker2==1, covariance
    gen float covname = r(cov_12)

    Click image for larger version

Name:	dataset3.jpg
Views:	1
Size:	153.0 KB
ID:	1472337









    Last edited by George Papadopoulos; 27 Nov 2018, 10:15.

  • #2
    That may make sense to people using your kind of data, but not to me.

    By column do you mean variable?

    Here is an odd fact: of the 20 people who have posted most on Statalist since 2014, only 4 are identifiably economists and so far as I can see none of those specialises in this kind of data.

    So to maximise attention you should give a better idea of what your data look like. Please do read the FAQ Advice especially #12 and come back with a data example making your structure much clearer.

    Comment


    • #3
      Dear Nick Cox,
      thanks for your advice.Yes, by column I mean variable
      dclose is the difference of Pt and Pt-1, where Pt is the price of a stock at time t
      dclose_lag is the lag of dclose
      ticker2 is the identifier for each stock
      And i need a new variable that will give me the covariance of dclose and dclose_lag for each stock

      Comment


      • #4
        Sorry, but without a data example I am not much wiser. rangestat (SSC) can calculate covariances. If that's not an answer, then best of luck that someone else can decode your question.

        Comment

        Working...
        X