Announcement

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

  • Matching Variable to HH member

    Hello,
    The ID_PERSON that I have is the respondent in the survey and ID_mil ID_fil is the identifier for their spouse's mother and father.

    Here the dummies for difficulty_walk, difficulty_toilet, difficulty_dressing and mobility_difficult are given for the respondent ( ie it shows whether the respondent has any difficulty in those activities)
    I would like to create separate dummies for the respondent's fil and mil that shows that a respondent's fil /mil had difficulty in walking and going to the toilet etc in the same row.
    How can I do that?
    I use STATA 14 MP.


    Code:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(ID_PERSON ID_fil ID_mil) float(difficulty_walk difficulty_toilet difficulty_dressing mobility_difficult)
    10201001002   102010010   102010010 0 0 0 0
    10201002009 10201002001 10201002002 0 0 0 0
    10201003002   102010030   102010030 0 0 0 0
    10201004002   102010040   102010040 0 0 0 0
    10201007002   102010070   102010070 0 0 0 0
    10201012002   102010120   102010120 0 0 0 0
    10201013002   102010130   102010130 0 0 0 0
    10201014002   102010140   102010140 0 0 0 0
    10201016004 10201016001 10201016002 0 0 0 0
    10201018005 10201018001 10201018002 0 0 0 0
    10201019002   102010190   102010190 0 0 0 0
    10202001002   102020010   102020010 0 0 0 0
    10202002002   102020020   102020020 0 0 0 0
    10202003002   102020030   102020030 0 0 0 0
    10202004002   102020040   102020040 0 0 0 0
    10202006004 10202006001 10202006002 0 0 0 0
    10202007004 10202007001 10202007002 0 0 0 0
    10202070104 10202070101 10202070102 1 0 0 1
    10202011002   102020110   102020110 0 0 0 0
    10202014002 10202014075 10202014006 0 0 0 0
    10202015002 10202015006 10202015007 0 0 0 0
    10202016002   102020160   102020160 0 0 0 0
    10202017002 10202017075 10202017007 0 0 0 0
    10202018002   102020180   102020180 0 0 0 0
    10202019002   102020190   102020190 0 0 0 0
    10203002002   102030020   102030020 0 0 0 0
    10203005002   102030050   102030050 0 0 0 0
    10203006009 10203006001 10203006002 0 0 0 0
    10203007002   102030070   102030070 0 0 0 0
    10203011002 10203011075 10203011006 0 0 0 0
    10203012002   102030120   102030120 0 0 0 0
    10203013003   102030130   102030130 0 0 0 0
    10203014004 10203014001 10203014002 0 0 0 0
    10203015003   102030150 10203015006 0 0 0 0
    10203016002   102030160   102030160 0 0 0 0
    10203017002   102030170   102030170 0 0 0 0
    10203019004 10203019001 10203019002 0 0 0 0
    10204001002 10204001075 10204001008 0 0 0 0
    10204004002   102040040   102040040 0 0 0 0
    10204006002   102040060   102040060 0 0 0 0
    10204007002   102040070   102040070 0 0 0 0
    10204008004 10204008001 10204008002 0 0 0 0
    10204009002   102040090   102040090 0 0 0 0
    10204090102 10204090175 10204090175 0 0 0 0
    10204012002   102040120   102040120 0 0 0 0
    10204013017   102040130   102040130 0 0 0 0
    10204017011 10204017001 10204017002 0 0 0 0
    10205002002   102050020   102050020 0 0 0 0
    10205007004 10205007001 10205007002 0 0 0 0
    10205009002   102050090   102050090 0 0 0 0
    10205011002   102050110   102050110 0 0 0 0
    10205012003 10205012001 10205012075 0 0 0 0
    10205130102 10205130175 10205130169 0 0 0 0
    10205013002   102050130   102050130 0 0 0 0
    10205150102 10205150108 10205150175 0 0 0 0
    10205015002 10205015008 10205015075 0 0 0 0
    10205016002   102050160   102050160 0 0 0 0
    10205017002   102050170   102050170 0 0 0 0
    10205018002   102050180   102050180 0 0 0 0
    10205019002   102050190   102050190 0 0 0 0
    10206001002   102060010   102060010 0 0 0 0
    10206002002   102060020   102060020 0 0 0 0
    10206003002 10206003075 10206003010 0 0 0 0
    10206004002   102060040   102060040 0 0 0 0
    10206006002 10206006075 10206006010 0 0 0 0
    10206007002   102060070   102060070 0 0 0 0
    10206008002   102060080   102060080 0 0 0 0
    10206009002   102060090   102060090 0 0 0 0
    10206011002   102060110   102060110 0 0 0 0
    10206012004 10206012001 10206012002 0 0 0 0
    10206014002   102060140   102060140 0 0 0 0
    10206015004 10206015001 10206015002 0 0 0 0
    10207001002 10207001075 10207001005 0 0 0 0
    10207002002 10207002075 10207002014 0 0 0 0
    10207003002   102070030   102070030 0 0 0 0
    10207004002   102070040   102070040 0 0 0 0
    10207005002 10207005028 10207005075 0 0 0 0
    10207006004 10207006001 10207006002 0 0 0 0
    10207007002   102070070   102070070 0 0 0 0
    10207011002   102070110   102070110 0 0 0 0
    10207015002   102070150   102070150 1 0 0 1
    10208030103 10208030101 10208030175 0 0 0 0
    10208005002   102080050   102080050 0 0 0 0
    10208006002   102080060   102080060 0 0 0 0
    10208007002   102080070   102080070 0 0 0 0
    10208009002   102080090   102080090 1 0 0 1
    10208010002   102080100   102080100 0 0 0 0
    10208011002   102080110   102080110 0 0 0 0
    10208120102 10208120175 10208120108 0 0 0 0
    10208012002 10208012075 10208012008 0 0 0 0
    10208130102 10208130175 10208130175 0 0 0 0
    10208013002   102080130   102080130 0 0 0 0
    10208014002   102080140   102080140 0 0 0 0
    10301020102 10301020175 10301020175 0 0 0 0
    10301004002   103010040   103010040 0 0 0 0
    10301007002   103010070   103010070 0 0 0 0
    10301090104 10301090101 10301090102 0 0 0 0
    10301013004 10301013075 10301013006 0 0 0 0
    10301015002   103010150   103010150 0 0 0 0
    10302001004 10302001075 10302001005 0 0 0 0
    end
    ------------------ copy up to and including the previous line ------------------

  • #2
    If you have data on ID_fil and ID_mil you can just join on those (though you'll need to adjust variable names to be different than the ID_PERSON).

    An issue is that ID_fil and ID_mil are identical. Thus, the data on those must be in independent datasets.

    Comment


    • #3
      I don't understand. How will I be able to code that?

      Comment


      • #4
        The ID_mil and ID_fil that are equal should not be considered. The matching should be only for those IDs that are formatted %012.0f

        Comment


        • #5
          Let's look at the second observation.
          10201002009 10201002001 10201002002

          Would 10201002001 and 10201002002 also be in this dataset, or a different one?


          Comment


          • #6
            Code:
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input double(ID_PERSON ID_fil ID_mil) float(difficulty_walk difficulty_toilet difficulty_dressing mobility_difficult)
            10201001002           .           . 0 0 0 0
            10201002009 10201002001 10201002002 0 0 0 0
            10201003002           .           . 0 0 0 0
            10201004002           .           . 0 0 0 0
            10201007002           .           . 0 0 0 0
            10201012002           .           . 0 0 0 0
            10201013002           .           . 0 0 0 0
            10201014002           .           . 0 0 0 0
            10201016004 10201016001 10201016002 0 0 0 0
            10201018005 10201018001 10201018002 0 0 0 0
            10201019002           .           . 0 0 0 0
            10202001002           .           . 0 0 0 0
            10202002002           .           . 0 0 0 0
            10202003002           .           . 0 0 0 0
            10202004002           .           . 0 0 0 0
            10202006004 10202006001 10202006002 0 0 0 0
            10202007004 10202007001 10202007002 0 0 0 0
            10202070104 10202070101 10202070102 1 0 0 1
            10202011002           .           . 0 0 0 0
            10202014002 10202014075 10202014006 0 0 0 0
            10202015002 10202015006 10202015007 0 0 0 0
            10202016002           .           . 0 0 0 0
            10202017002 10202017075 10202017007 0 0 0 0
            10202018002           .           . 0 0 0 0
            10202019002           .           . 0 0 0 0
            10203002002           .           . 0 0 0 0
            10203005002           .           . 0 0 0 0
            10203006009 10203006001 10203006002 0 0 0 0
            10203007002           .           . 0 0 0 0
            10203011002 10203011075 10203011006 0 0 0 0
            10203012002           .           . 0 0 0 0
            10203013003           .           . 0 0 0 0
            10203014004 10203014001 10203014002 0 0 0 0
            10203015003           . 10203015006 0 0 0 0
            10203016002           .           . 0 0 0 0
            10203017002           .           . 0 0 0 0
            10203019004 10203019001 10203019002 0 0 0 0
            10204001002 10204001075 10204001008 0 0 0 0
            10204004002           .           . 0 0 0 0
            10204006002           .           . 0 0 0 0
            10204007002           .           . 0 0 0 0
            10204008004 10204008001 10204008002 0 0 0 0
            10204009002           .           . 0 0 0 0
            10204090102 10204090175 10204090175 0 0 0 0
            10204012002           .           . 0 0 0 0
            10204013017           .           . 0 0 0 0
            10204017011 10204017001 10204017002 0 0 0 0
            10205002002           .           . 0 0 0 0
            10205007004 10205007001 10205007002 0 0 0 0
            10205009002           .           . 0 0 0 0
            10205011002           .           . 0 0 0 0
            10205012003 10205012001 10205012075 0 0 0 0
            10205130102 10205130175 10205130169 0 0 0 0
            10205013002           .           . 0 0 0 0
            10205150102 10205150108 10205150175 0 0 0 0
            10205015002 10205015008 10205015075 0 0 0 0
            10205016002           .           . 0 0 0 0
            10205017002           .           . 0 0 0 0
            10205018002           .           . 0 0 0 0
            10205019002           .           . 0 0 0 0
            10206001002           .           . 0 0 0 0
            10206002002           .           . 0 0 0 0
            10206003002 10206003075 10206003010 0 0 0 0
            10206004002           .           . 0 0 0 0
            10206006002 10206006075 10206006010 0 0 0 0
            10206007002           .           . 0 0 0 0
            10206008002           .           . 0 0 0 0
            10206009002           .           . 0 0 0 0
            10206011002           .           . 0 0 0 0
            10206012004 10206012001 10206012002 0 0 0 0
            10206014002           .           . 0 0 0 0
            10206015004 10206015001 10206015002 0 0 0 0
            10207001002 10207001075 10207001005 0 0 0 0
            10207002002 10207002075 10207002014 0 0 0 0
            10207003002           .           . 0 0 0 0
            10207004002           .           . 0 0 0 0
            10207005002 10207005028 10207005075 0 0 0 0
            10207006004 10207006001 10207006002 0 0 0 0
            10207007002           .           . 0 0 0 0
            10207011002           .           . 0 0 0 0
            10207015002           .           . 1 0 0 1
            10208030103 10208030101 10208030175 0 0 0 0
            10208005002           .           . 0 0 0 0
            10208006002           .           . 0 0 0 0
            10208007002           .           . 0 0 0 0
            10208009002           .           . 1 0 0 1
            10208010002           .           . 0 0 0 0
            10208011002           .           . 0 0 0 0
            10208120102 10208120175 10208120108 0 0 0 0
            10208012002 10208012075 10208012008 0 0 0 0
            10208130102 10208130175 10208130175 0 0 0 0
            10208013002           .           . 0 0 0 0
            10208014002           .           . 0 0 0 0
            10301020102 10301020175 10301020175 0 0 0 0
            10301004002           .           . 0 0 0 0
            10301007002           .           . 0 0 0 0
            10301090104 10301090101 10301090102 0 0 0 0
            10301013004 10301013075 10301013006 0 0 0 0
            10301015002           .           . 0 0 0 0
            10302001004 10302001075 10302001005 0 0 0 0
            end
            ------------------ copy up to and including the previous line ------------------

            Comment


            • #7
              It would be in the same dataset.

              Comment


              • #8
                Second observation:

                Would 10201002001 and 10201002002 also be a ID_PERSON in this dataset?

                Comment


                • #9
                  I think the example below will make it clearer.
                  Yes the ID_mil and ID_fil are present as ID_PERSON in the same dataset.

                  for eg) for the fifth observation, that respondent's fil is the fourth observation.

                  Code:
                  ----------------------- copy starting from the next line -----------------------
                  
                  
                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input double(ID_PERSON ID_fil ID_mil) float(difficulty_walk difficulty_toilet difficulty_dressing mobility_difficult)
                  10201001002           .           . 0 0 0 0
                  10201001001           .           . 0 0 0 0
                  10201002015           .           . 0 0 0 0
                  10201002001           .           . 0 0 0 0
                  10201002009 10201002001 10201002002 0 0 0 0
                  10201002004 10201002001           . 0 0 0 0
                  10201002013 10201002001           . 0 0 0 0
                  10201003002           .           . 0 0 0 0
                  10201003001           .           . 0 0 0 0
                  10201004002           .           . 0 0 0 0
                  10201004001           .           . 0 0 0 0
                  10201005003 10201005001 10201005075 0 0 0 0
                  10201006014 10201006001           . 0 0 0 0
                  10201006001           .           . 0 0 0 0
                  10201007001           .           . 0 0 0 0
                  10201007002           .           . 0 0 0 0
                  10201008002           .           . 0 0 0 0
                  10201008001           .           . 0 0 0 0
                  10201009002           .           . 0 0 0 0
                  10201010111           .           . 0 0 0 0
                  10201010102           .           . . . . 0
                  10201010107           .           . 0 0 0 0
                  10201011001           .           . 0 0 0 0
                  10201012001           .           . 0 0 0 0
                  10201012002           .           . 0 0 0 0
                  10201013002           .           . 0 0 0 0
                  10201013001           .           . 0 0 0 0
                  10201014002           .           . 0 0 0 0
                  10201014001           .           . 0 0 0 0
                  10201016004 10201016001 10201016002 0 0 0 0
                  10201016002           .           . 0 0 0 0
                  10201016001           .           . 0 0 0 0
                  10201017001           .           . 0 0 0 0
                  10201018005 10201018001 10201018002 0 0 0 0
                  10201018010           .           . 0 0 0 0
                  10201018002           .           . 0 0 0 0
                  10201019002           .           . 0 0 0 0
                  10201019001           .           . 0 0 0 0
                  10201020113 10201020101           . 0 0 0 0
                  10201020101           .           . 0 0 0 0
                  10201020116           .           . 0 0 0 0
                  10201030102 10201030169 10201030175 0 0 0 0
                  10201040102 10201040175 10201040169 0 0 0 0
                  10201050102 10201050175 10201050175 0 0 0 0
                  10201060107 10201060101           . 0 0 0 0
                  10201070102 10201070175 10201070169 0 0 0 0
                  10201080102           .           . 0 0 0 0
                  10201080101           .           . 0 0 0 0
                  10201090201           .           . 1 0 0 1
                  10201100113           .           . 1 0 0 1
                  10201100109           .           . 0 0 0 0
                  10201120102 10201120169 10201120169 0 0 0 0
                  10201130102 10201130169 10201130169 0 0 0 0
                  10201140102 10201140175 10201140169 0 0 0 0
                  10201160102 10201160175           . 0 0 0 0
                  10201160104 10201160101 10201160102 0 0 0 0
                  10201170102 10201170175 10201170175 1 1 0 1
                  10201180105 10201180175 10201180111 0 0 0 0
                  10201180111           .           . 0 0 0 0
                  10201190102 10201190169 10201190169 0 0 0 0
                  10201200104 10201200101 10201200102 0 0 0 0
                  10201200102 10201200175           . 0 0 0 0
                  10202001001           .           . 0 0 0 0
                  10202001002           .           . 0 0 0 0
                  10202002002           .           . 0 0 0 0
                  10202002001           .           . 0 0 0 0
                  10202003001           .           . 0 0 0 0
                  10202003002           .           . 0 0 0 0
                  10202004001           .           . 0 0 0 0
                  10202004002           .           . 0 0 0 0
                  10202005002           .           . 0 0 0 0
                  10202006002           .           . 0 0 0 0
                  10202006004 10202006001 10202006002 0 0 0 0
                  10202007006           .           . 0 0 0 0
                  10202007002           .           . 0 0 0 0
                  10202007004 10202007001 10202007002 0 0 0 0
                  10202007001           .           . 0 0 0 0
                  10202008005           .           . 0 0 0 0
                  10202008006           .           . 0 0 0 0
                  10202008001           .           . 0 0 0 0
                  10202008004           .           . 0 0 0 0
                  10202008002           .           . 0 0 0 0
                  10202008003           .           . 0 0 0 0
                  10202009002           .           . 0 0 0 0
                  10202009001           .           . 0 0 0 0
                  10202011002           .           . 0 0 0 0
                  10202011001           .           . 0 0 0 0
                  10202012004 10202012001           . 0 0 0 0
                  10202012016 10202012008           . 0 0 0 0
                  10202012002           .           . 0 0 0 0
                  10202012008           .           . 0 0 0 0
                  10202012009           .           . 0 0 0 0
                  10202013002           .           . 0 0 0 0
                  10202013004 10202013001           . 0 0 0 0
                  10202013001           .           . 0 0 0 0
                  10202014002 10202014075 10202014006 0 0 0 0
                  10202015002 10202015006 10202015007 0 0 0 0
                  10202015007           .           . 0 0 0 0
                  10202016002           .           . 0 0 0 0
                  10202016001           .           . 0 0 0 0
                  end

                  Comment


                  • #10
                    There are a few ways to proceed, but this is one:

                    1. take the master data.
                    2. drop id_fil and id_mil.
                    3. rename ID_PERSON id_fil
                    4. rename difficulty_* difficulty_*_fil
                    5. rename mobility_* mobility_*_fil
                    6 save fil_data
                    7. ren*_fil *_mil
                    8. save mil_data

                    Now, in you master data,

                    joinby id_fil using fil_data
                    joinby id_mil using mil_data

                    The other ways is to keep joining on the master data, but rename the id variables and x variables as needed.
                    ren ID_PERSON id_temp
                    ren diff* diff_temp
                    ren mob* mob*_temp
                    ren id_fil ID_PERSON
                    joinby ID_PERSON using masterdata
                    etc....

                    so, a lot of renaming at each step.













                    Comment


                    • #11
                      I really appreciate your time and help.
                      Unfortunately the joinby command limited the observations by a great deal, Hence I employed the following command to merge the two datatsets to the master

                      merge m:1 ID_fil using fil_data, keep(master match) nogen
                      merge m:1 ID_mil using mil_data, keep(master match) nogen

                      Comment


                      • #12
                        Yup. I'd use _merge(_merge_fil) and _merge(_merge_mil) just in case you need it (say, to replace missing values).

                        Comment


                        • #13
                          Thank you very much.

                          Comment

                          Working...
                          X