Announcement

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

  • Advanced Fillin

    Hello,

    I am trying to create observations. I have monthly U.S. import data by product level and by exporting country. All of my observations right now are non-zero, thus, data points only exist where there are import data. I want to create observations where monthly data would be 0 if there was no import in given period. I know that I can use 'fillin' code to do something similar. (fillin exporter period product) But I don't want to create zero's where a given exporter has never exported a certain product. I only want to create zeros for exporters if they have experience exporting certain products but do not have data points in certain months because they didn't export in those months.

    Can someone help me with how to selectively create data points?

    Thank you.

    Sincerely,
    Soyoung

  • #2
    There probably are numerous approaches, but you could consider something like the following.

    1. use the original dataset and then, using fillin, create the zero data for each exporter for each product for each month (you've already done this step)

    2. save that to a temporary dataset file

    3. use the original dataset again and then, using contract exporter product, freq(discard), create a dataset resident in memory of combinations of exporters and products for which there exits at least one month of export

    4. finally, use merge exporter product using <temporary dataset>, assert(match using) keep(match) which will eliminate those exporter-product combinations that do not exist for at least one month

    Comment


    • #3
      Slight correction: to use the modern syntax for -merge-, supply the join's cardinality.
      Code:
      merge 1:m exporter product using <temporary dataset>, assert(match using) keep(match)
      If you had tried without it, Stata would have given you a warning message that would have led you to the right path.

      Comment


      • #4
        Thank you so much! It worked perfectly!

        Comment

        Working...
        X