Announcement

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

  • Clustering by two variables if one is missing

    Hi all,

    I've had a look at the manual and I can't seem to find what I need...

    I'm looking to cluster by mpid (mothers id) as my population of interest is children, and that's the closest thing I have to household. However, I do not want to exclude households who only live with their father - as mpid would be missing. Ideally I need a model that will cluster by mpid and if not then fpid (fathers id).

    Something like:
    Code:
    xtreg selfesteem ypsex dvage divorcemo emotabusemo physpunishtmo mwbmo, re, vce(cluster mpid [missing] fpid)

  • #2
    How about this:

    Code:
    gen cluster_variable = mpid
    replace cluster_variable = fpid if missing(cluster_variable)
    xtreg ...., vce(cluster cluster_variable)

    Comment


    • #3
      Genius, I'll try it out now.

      Many thanks

      Em

      Comment


      • #4
        Hi Clyde,

        It has somewhat worked - but because mpid is a unique ID (has duplications as it is the mothers id, so multiple adolescents can have the same mpid) it seems to have added on a number to the end see code.

        This is just for:
        Code:
        g clusterhh = mpid
        Code:
         
        mpid clusterhh
        68014287 68014288
        68028567 68028568
        68037407 68037408
        68041487 68041488
        68041487 68041488
        68046927 68046928
        68046927 68046928
        68056451 68056448
        Do you know how I can stop it doing this?

        Comment


        • #5
          The most likely problem I can see here is a precision issue. When you -g clusterhh = mpid-, by default clusterhh is generated as a float. It looks to me as if the ids have too many digits to be stored exactly in a float, so "rounding" error is occurring. (Float can only hold up to 7 digits without loss of precision.) If I'm right, you can fix this by changing it to -gen long clusterhh = mpid-. (The -replace- statement will not require any modification.)

          Comment


          • #6
            Thanks Clyde I'll give that a go -

            Comment


            • #7
              Hi Clyde

              Sorry for the late response, I got caught up in some xtoverid stuff! Yes that worked perfectly thanks and noted.

              Emily

              Comment

              Working...
              X