Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Robson Glasscock <[email protected]> |

To |
[email protected] |

Subject |
Re: st: Change variable |

Date |
Thu, 15 Sep 2011 11:00:11 -0400 |

If File 2 really only had one observation then I don't think you would get the error when you do the m:1 merge. Your variables either aren't set up the way you described earlier in the thread or there are duplicates in File 2. The problem is either one or the other and a m:1 merge is the way to go here. best, Robson Glasscock On Thu, Sep 15, 2011 at 10:45 AM, Ay <[email protected]> wrote: > Yes, multiple observation in file1. > If you see id2=2 has two observations that recorded each educational level of that child. > > File 2 is only one obs. > > Could i simply copy and paste into a new file all data in file1 based on the educlevel? So i'll have two new files as an extract for each educlevel with single observation. And then merge these new files before merging again to file 2. > > I am thinking to reshape but dont know the correct way to do it. > > Or is there any other alternative way to do this? > > > Regards, > Yun > > > > > > On 15 Sep 2011, at 23:47, Robson Glasscock <[email protected]> wrote: > >> I understand that the id number is the number of the respondent and >> not the number of children in the house. >> >> To me, the unique id is a combination of the household and the >> respondent id. File 1 is panel data that tracks educational level and >> school type changes for each respondent in a particular household. But >> you're tracking these changes for a particular respondent in a >> particular household- so that's your unique identifier. >> >> What you're trying to do here is merge in the "ethnicity" and >> "livings" data for each child along with the data in File 1 that has >> information on how that child's education changed over time. >> >> What I'm guessing is that in File 2 you do not actually only have one >> observation for each respondent in each household. If there are >> multiple observations in File 2, then a m:1 merge won't work. >> >> If you have multiple observations in File 2 for the same respondent, >> then you may be able to retain only one observation for each >> respondent in File 2. The "ethnicity" variable won't vary in File 2 >> even if you have multiple observations. What about "livings"? Does >> that change? If it doesn't and there are multiple observations per >> respondent, then you can simply retain only one observation per >> individual in File 2 and redo the merge we discussed previously. >> >> best, >> Robson Glasscock >> >> On Thu, Sep 15, 2011 at 9:25 AM, Ay <[email protected]> wrote: >>> Dear Robson, >>> >>> Thank you for replying. >>> I've tried m:1, it showed that ...is not unique id. >>> When i check it using isid, file1 includes educlevel as unique id. Hence, there would be the same child with different educlevel. So, this child has 2 obs in the file1. >>> Actually, the child (id2) does not mean the number of child in the household, but number of respondent. >>> I have searched online about this, but still does not get an answer. >>> >>> Thank you, >>> >>> Yun >>> >>> >>> >>> >>> On 15 Sep 2011, at 22:06, Robson Glasscock <[email protected]> wrote: >>> >>>> Hi Ay, >>>> >>>> No need for an apology. This is a m:1 merge using household(id1) and >>>> child(id2). >>>> >>>> Sort File 1 on household and child. Save it. >>>> Sort File 2 on household. Save it. >>>> >>>> Go into file_1 and type: >>>> >>>> merge m:1 household child using File_2.dta >>>> >>>> Note that it looks to me from the data you provided that household 2 >>>> has child 4 and child 3 in File 1, but File 2 only has child 1. Also, >>>> household 3 in File 1 has child 5, but household 3 in File 2 has child >>>> 2. These will show up as observations where _merge != 3 after you >>>> merge the files. >>>> >>>> best, >>>> Robson Glasscock >>>> >>>> On Thu, Sep 15, 2011 at 6:02 AM, Ay <[email protected]> wrote: >>>>> Dear Robson, >>>>> >>>>> My apologize about my unclear question. >>>>> >>>>> I try to list the variables and data in rows rather than in colomn. >>>>> >>>>> File 1 >>>>> Household(id1)-> >>>>> 1, 1, 1, 2, 2, 2, 3, ... >>>>> >>>>> Child(id2)-> >>>>> 2, 2, 3, 4, 3, 3, 5, ... >>>>> >>>>> Educlevel-> >>>>> 2, 1, 1, 2, 2, 1, 1, ... >>>>> >>>>> X3(schooltype)-> >>>>> a, b, a, b, a, a, b, ... >>>>> >>>>> X4(repetition) >>>>> 2, 2, 2, 2, 2, 2, 2, ... >>>>> >>>>> Educlevel in strings. >>>>> Educlevel=1 is primary school. >>>>> Educlevel=2 is secondary level. >>>>> A child may have secondary level and thus have records for his primary level along with other variables in file1. >>>>> >>>>> >>>>> File 2 >>>>> Household(id1)-> >>>>> 1, 2, 3, ... >>>>> >>>>> Child(id2)-> >>>>> 3, 1, 2, ... >>>>> >>>>> X3(ethnicity) >>>>> 1, 3, 2, ... >>>>> >>>>> X4(livings)-> >>>>> 1, 2, 2, ... >>>>> >>>>> In file 2 only single obs. >>>>> >>>>> I hope this is clearer. >>>>> >>>>> Thank you. >>>>> >>>>> Regards, >>>>> >>>>> Yun >>>>> >>>>> >>>>> On 11 Sep 2011, at 01:53, Robson Glasscock <[email protected]> wrote: >>>>> >>>>>> So File 1 is a panel data set that records each individual's >>>>>> educational level over time? If that is the case, and if File 2 is >>>>>> also panel data, then a 1:1 merge based on x1(unique id) and x3(time >>>>>> period) could be done. >>>>>> >>>>>> If File 2 is not panel data, then you're looking at a m:1 merge based >>>>>> on x1(unique id). >>>>>> >>>>>> If this doesn't solve the problem, I think you should include an >>>>>> example of the observations in each of your files on your next post. >>>>>> I'm still struggling a bit to picture the contents of your files. >>>>>> >>>>>> On Sat, Sep 10, 2011 at 9:20 AM, Ay <[email protected]> wrote: >>>>>>> Dear Robson, >>>>>>> >>>>>>> Thank you for replying. >>>>>>> >>>>>>> Actually, >>>>>>> File 1: >>>>>>> x1 (unique id) >>>>>>> x2 (educational level) >>>>>>> >>>>>>> File 2 >>>>>>> x1 (unique id) >>>>>>> >>>>>>> >>>>>>> In file 2, x1 & x2 together are unique id. All of the variables are in strings. >>>>>>> >>>>>>> I could not merge file1 and file 2 since x2 is the educational level in which an individual would have more than 1 level/type. >>>>>>> >>>>>>> Thank you, >>>>>>> >>>>>>> Yun >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> On 10 Sep 2011, at 22:56, Robson Glasscock <[email protected]> wrote: >>>>>>> >>>>>>>> I'm having a hard time understanding the structure of your "first >>>>>>>> file" and your "second file. Do your files looks like this: >>>>>>>> >>>>>>>> File 1: >>>>>>>> x1 >>>>>>>> (unique id + educational level) >>>>>>>> >>>>>>>> File 2: >>>>>>>> x1 >>>>>>>> (unique id) >>>>>>>> >>>>>>>> so that File 1 contains a concatenated variable? >>>>>>>> >>>>>>>> If File 1 has one variable, x1, that is concatenated, then I don't >>>>>>>> think you need to merge the files together to get what you want. You >>>>>>>> would just need to split x1(unique id + educational level) into >>>>>>>> x1(unique id) and x2(educational level). The substr function may be >>>>>>>> used to do this. >>>>>>>> >>>>>>>> -help substr- >>>>>>>> >>>>>>>> best, >>>>>>>> Robson Glasscock >>>>>>>> >>>>>>>> On Fri, Sep 9, 2011 at 5:27 PM, Ay <[email protected]> wrote: >>>>>>>>> >>>>>>>>> I am using stata 11.0 >>>>>>>>> >>>>>>>>> How can i generate or change a variable that contains for instance, educational level or father and mother as 'Type'? >>>>>>>>> The variables are in strings format. >>>>>>>>> >>>>>>>>> The reason i am asking this question is that, i want to merge these 'type' variable (var B) with other variable. >>>>>>>>> I could not do this since the second file only has variable A as individual id variable. While in the first file, it has var A and var B ('type' or level variable) as unique Id. >>>>>>>>> >>>>>>>>> If anyone knows other ways besides generating the type variable before merging, I really appreciate it. >>>>>>>>> >>>>>>>>> Variable a >>>>>>>>> 1,2,1,1,2,3,3 >>>>>>>>> >>>>>>>>> Variable b(type) >>>>>>>>> A,A,B,C,B,C,A >>>>>>>>> >>>>>>>>> Many thanks. >>>>>>>>> >>>>>>>>> Regards, >>>>>>>>> >>>>>>>>> Yun >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> * >>>>>>>>> * For searches and help try: >>>>>>>>> * http://www.stata.com/help.cgi?search >>>>>>>>> * http://www.stata.com/support/statalist/faq >>>>>>>>> * http://www.ats.ucla.edu/stat/stata/ >>>>>>>> >>>>>>>> * >>>>>>>> * For searches and help try: >>>>>>>> * http://www.stata.com/help.cgi?search >>>>>>>> * http://www.stata.com/support/statalist/faq >>>>>>>> * http://www.ats.ucla.edu/stat/stata/ >>>>>>> >>>>>>> * >>>>>>> * For searches and help try: >>>>>>> * http://www.stata.com/help.cgi?search >>>>>>> * http://www.stata.com/support/statalist/faq >>>>>>> * http://www.ats.ucla.edu/stat/stata/ >>>>>>> >>>>>> >>>>>> * >>>>>> * For searches and help try: >>>>>> * http://www.stata.com/help.cgi?search >>>>>> * http://www.stata.com/support/statalist/faq >>>>>> * http://www.ats.ucla.edu/stat/stata/ >>>>> >>>>> * >>>>> * For searches and help try: >>>>> * http://www.stata.com/help.cgi?search >>>>> * http://www.stata.com/support/statalist/faq >>>>> * http://www.ats.ucla.edu/stat/stata/ >>>>> >>>> >>>> * >>>> * For searches and help try: >>>> * http://www.stata.com/help.cgi?search >>>> * http://www.stata.com/support/statalist/faq >>>> * http://www.ats.ucla.edu/stat/stata/ >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/statalist/faq >>> * http://www.ats.ucla.edu/stat/stata/ >>> >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Change variable***From:*Ay <[email protected]>

**Re: st: Change variable***From:*Robson Glasscock <[email protected]>

**Re: st: Change variable***From:*Ay <[email protected]>

**Re: st: Change variable***From:*Robson Glasscock <[email protected]>

**Re: st: Change variable***From:*Ay <[email protected]>

**Re: st: Change variable***From:*Robson Glasscock <[email protected]>

**Re: st: Change variable***From:*Ay <[email protected]>

**Re: st: Change variable***From:*Robson Glasscock <[email protected]>

**Re: st: Change variable***From:*Ay <[email protected]>

- Prev by Date:
**RE: st: Bootstrapping & clustered standard errors (-xtreg-)** - Next by Date:
**st: Importing String Variables ruins access to variable categories** - Previous by thread:
**Re: st: Change variable** - Next by thread:
**st: My stata won't -tab- with my value labels - why?** - Index(es):