Announcement

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

  • use "by" command or "if" condition with matchit in stata

    Hi,

    I am merging two data set based on Districts names in stata. Though matchit work fine in case there is no IF condition on Districts names.
    However I cannot use a by or if conditionwith matchit in stata.

    An example of the scenario is:
    by countrynames: matchit iddistrict district using "abc", idu(id) txtu(district) sim(soundex)
    or
    matchit iddistrict district using "abc", idu(id) txtu(district) sim(soundex) if countrynames matches

    Any thought?
    Thanks

  • #2
    Cross-posted at https://stackoverflow.com/questions/...ckage-in-stata

    Our policy on cross-posting is explicit in the FAQ Advice everybody is asked to read before posting. You are asked to tell us about it.

    I commented as follows on Stack Overflow:

    The second syntax would be illegal as the if condition is misplaced. But if you want to apply matchit to a subset, drop the other observations first. If you want to apply matchit separately to different subsets, run it repeatedly on those subsets as separate datasets.

    I don't work in this territory so can't comment on what is good or poor procedure otherwise.
    Last edited by Nick Cox; 06 Apr 2018, 04:22.

    Comment


    • #3
      Unfortunately matchit does not allow for by or if clauses. But this can be mimicked with some lines of codes:

      1) keep the unique district names in the two sources
      2) match these using matchit
      3) drop those not meeting the desired similarity threshold
      4) merge with the original two datasets
      5) drop all observations where the countries don't match

      A similar example is given here: https://www.statalist.org/forums/for...47#post1441347

      In the case of countries, you can also reapply matchit in (5) using the columns syntax. This will prevent some misspellings of country names.

      Comment


      • #4
        Sorry Nick Cox for posting same question across forum. I will be careful in my future posting.
        Thank you for suggestions.

        Thank you Julio Raffo. The links you suggested helped me figure out a way to resolve the problem.
        I used the joinby command before to match in groups and apply the command later.

        Comment


        • #5
          As explained in the FAQ, cross-posting is not something you need to apologise for. It's just something that you are asked to explain.

          Comment


          • #6
            Policy on cross posting is explained below,

            Its is perfectly fine to cross-post a question on several forum. However, when one do so, should provide a searchable URL link to the archives.
            This way people interested in your question would find answer easily and avoid similar comments/questions. It save time for everyone.

            Comment

            Working...
            X