Announcement

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

  • Running Diebold Mariano test using panel data.

    Hi everyone,

    I am totally new here and very new to Stata, nice to meet you all. This maybe a very simple question, I am sorry if this makes you feel that you are wasting your time. Your help would be very appreciated. I have a panel data with 320 financial products and 20 quarters of data. There are two sets of pricing predictions and the real price trend for each product. The goal of the test is to see which pricing function predicted the real price better in sample. As far as I know and tried, DM test can only run on time series data, so I tried to run the test separately for each product as a time series test, using loop and statsby statement. The code is like the following, Stata says there is repeated time values in sample. But I double checked that there is no duplicated time for each id.

    forvalues i = 1(1)320 {
    if id == `i' {
    tsset quarter
    dmariano ln_price ln_VC ln_VT
    }
    }

    Can someone show me to the right direction, Thanks.


    Boheng


  • #2
    Welcome to Statalist, Boheng.

    The two problems I see in your code are

    1) tsset will not accept repeated time values, but since you have panel data, you can use xtset.

    2) You have mistaken the if command with the if qualifier. The latter is the appropriate way of restricting a command to run on a subset of observations.

    With that in mind, possibly this will start you in a useful direction. Lacking sample data to test it on, I can't be sure.
    Code:
    xtset id quarter
    forvalues i = 1(1)320 {
    dmariano ln_price ln_VC ln_VT if id == `i'
    }
    With that said, you'll improve your subsequent posts if you take a little time to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

    Comment


    • #3
      Thank you so much William for prompt response. I tried your code and I believe I experimented with similar code too. I don't know if this is the feature of the dmariano package or stata. Once I xtset, dmariano command just think of the data as panel data and wouldn't run, even if I am actually running time series test with in each id. Also thank for the suggestions of using the forum, I'll read them.

      Comment


      • #4
        Then perhaps this will help.
        Code:
        forvalues i = 1(1)320 {
        preserve
        quietly keep  if id == `i'
        display as result "id `i'"
        quietly tsset quarter
        dmariano ln_price ln_VC ln_VT if id == `i'
        restore
        }

        Comment


        • #5
          The code works great. Thank you William. You have a good day.

          Comment

          Working...
          X