Announcement

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

  • merge

    Hi everyone,

    My panel data seems like (part of):
    gvkey datadate fyear at(total asset) equity ni (net income)
    001010 30dec 1996 1996 100 100 100
    001010 30dec 1997 1997 150 150 150
    001013 30jun 1996 1996 ... ... ...
    001013 30jun 1997 1997 ... ... ...
    001034 30mar 1996 1996 ... ... ...
    001034 30mar 1997 1997 ... ... ...

    I have to calculate the change in equity and net income for the year 1997 and the data of 1996 is just to calculate and at the end I have to drop all of the observations of the year 1996. Firstly, I have to include firms with a sale >0 so I have use the code ''keep if sale > 0''. The problem is that some observations in 1997 are removed because of sales<0 while observations in 1996 are kept. I want to drop observations in 1996 if the observations in 1997 are not exist anymore but I don't know how to do that and with which code. Could someone help me to solve this problem? Thank you very much!

    Kind regard,

    Cindy Donald



  • #2
    Cindy, your post is filled with mistakes, incomplete ideas, and grammatical errors, which makes it very difficult to understand what you are asking. Here is just one example:

    The problem is that some observations in 1997 are removed because of sales<0
    But sales can't be less than 0, right? So you mean equal to 0?

    The problem is that some observations in 1997 are removed because of sales<0 while observations in 1996 are kept. I want to drop observations in 1996 if the observations in 1997 are not exist anymore but I don't know how to do that and with which code.
    So if I've correctly managed to reason through this sudoko-esque puzzle of a post, you like to remove all observations of that firm previous to or including the given year? So if a firm has no sales in 1997, you want to remove observations for that firm in 1997 and for all years previous to 1997? I think something like this might work:

    Code:
    foreach year in 1996/1997 {
        drop if sale == 0 &  fyear <= `year'
    }
    Of course, the above assumes you only have data for years 1996 and 1997, as your example data implies.

    Cindy, your post is a minefield for those of us who try to answer questions. I'm taking a guess at what you are talking about, a proverbial shot in the dark, and experience tells me that 9 times out of 10, you're going to respond by telling me that I'm wrong and that my code "doesn't work," and that's all, without ever clearly explaining what you want to do. This is why you haven't received any response yet today: experienced posters know that it's generally not worth answering questions like yours. More to the point, I strongly suspect there are possible conceptual problems with your strategy, but it is simply not clear from the way you asked this question. Take your title for instance: your post has absolutely nothing to do with merging data or the -merge- command. Why would you put the word "merge" in your title? I implore you to review the FAQ at the top of the page, to familiarize yourself with the -dataex- command, and to think very carefully about how to clearly and explicitly describe the problem you are having and how you would like to solve it. The more effort you put into asking questions, the more likely you are to get a clean and effective solution.

    Comment


    • #3
      Dear Schaefer,

      My apologies for the inconvenience and thanks for your response.

      When sales are equal to 0 or there are missing values in the observations, then the row has been removed. But I have faced a problem that for example the row gvkey 001055 fyear 1996 is kept while the row gvkey 001055 fyear 1997 is removed. I have to calculate the change in equity for gvkey 001055 in 1997 so I need the obeservation in 1996. Or it could be happen that gvkey 001081 fyear 1997 is kept but there is no observation for gvkey 001081 fyear 1996.
      I would like to keep the observations if there is a match between gvkey both in 1996 and 1997. It means that for instance gvkey 001050 appears in 1996 and 1997, so this one I would like to keep. But for gvkey 001055 and 001081, there are no observations after or previous year and I would like to remove theses observations in my dataset. My question is, is there a way to do it and how?
      I am thinking about xtbalance or bysort but I am not sure about it.

      gvkey datadate fyear sale
      001050 31dec1996 1996 9.848000000000001
      001050 31dec1997 1997 14.531
      001055 31dec1996 1996 2103.643
      001056 30jun1996 1996 74.367
      001056 30jun1997 1997 94.29900000000001
      001072 31mar1997 1996 1126.178
      001072 31mar1998 1997 1267.653
      001073 31dec1996 1996 1
      001078 31dec1996 1996 11013.46
      001078 31dec1997 1997 11883.462
      001081 31dec1997 1997 3747

      Kind regards,

      Cindy Donald


      Comment


      • #4
        I thought I understood, but then I saw gvkey 001072 in 1997 and 1998 instead of 1996 and 1997. So are there more than 2 years of data? Do some gvkeys have 3 (or more) years of data (1996 and 1997 and 1998)? Or does every gvkey have either 1 year of data or 2 years of data in successive years (1996 and 1997 or 1997 and 1998 but not 1996 and 1998 with no 1997 between)?

        Comment


        • #5
          On Statalist, we most commonly deal in data and code instead of guess work. The dataex command showsus your dataset exactly as you see it. Therefore, a typed out dataset is useless. Please, do present your ACTUAL dataset, using the dataex command. Also, show us the code you've tried so far (again, within the code delimiters). At present, as grandmama would say, I haven't the foggiest idea what the problem is, and I'm also unclear about what it is you want. The most I understood is that 1996 observations should be dropped, but that's it.

          Comment

          Working...
          X