Bookmark and Share

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]

Re: st: matching children and parents


From   Robert Picard <[email protected]>
To   [email protected]
Subject   Re: st: matching children and parents
Date   Wed, 12 Jun 2013 16:35:10 -0400

Why not simply merge by person identifiers. There's a bit of overhead
to setup the merge but otherwise it is pretty straightforward.

* --------------- begin example ---------------------------
clear
input family person father mother age education
 1 1001    .    . 45 12
 1 1002    .    . 47 16
 1 1003 1001 1002 10  4
 1 1004 1001 1002 11  5
 1 1005 1001 1002 12  6
 2 2001    .    . 52 11
 2 2002    . 2001 24 10
 2 2003    . 2002  7  2
end

list, sepby(family) noobs

preserve

keep person age education
rename (person age education) (mother age_m edu_m)
tempfile mothers
save "`mothers'"

rename (mother age_m edu_m) (father age_f edu_f)
tempfile fathers
save "`fathers'"

restore

merge m:1 mother using "`mothers'", keep(master match) nogen
merge m:1 father using "`fathers'", keep(master match) nogen

sort family person
list, sepby(family) noobs
* --------------- end example -----------------------------

On Wed, Jun 12, 2013 at 1:23 PM, Jeph Herrin <[email protected]> wrote:
>
> Unique is not such an issue, since presumably if you want to lookup a value, there is only a single value to be looked up. matsize is a bigger concern, though. One should be able to get around it with via mata but I haven't tried to work it out.
>
>
> On 6/12/2013 11:54 AM, Nick Cox wrote:
>>
>> -matsize- limits may bite. See -help limits-.
>> Nick
>> [email protected]
>>
>>
>>
>> On 12 June 2013 16:50, Nick Cox <[email protected]> wrote:
>>>
>>> This is an attractive idea.  The restriction Jeph flags may not bite
>>> hard as you should be able to use e.g. -egen, group()- to get unique
>>> identifiers.
>>>
>>>
>>> Nick
>>> [email protected]
>>>
>>>
>>> On 12 June 2013 13:48, Jeph Herrin <[email protected]> wrote:
>>>>
>>>> The lookup problem is one I often run into in Stata. That is, retrieving a
>>>> value for a variable using a (unique!) identifier from another.
>>>>
>>>> One solution I have used is to store the variable of interest in a matrix.
>>>> If (!) your ID is a unique string, then you can
>>>>
>>>>    mkmat education, matrix(E) rownames(ID)
>>>>    gen motheredu= el("E",rownumb("E",motherID),1)
>>>>
>>>>
>>>> hth,
>>>> Jeph
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 6/12/2013 3:45 AM, Andrea Smurra wrote:
>>>>>
>>>>>
>>>>> Hello everyone.
>>>>> I am dealing with a big household survey.
>>>>> I am interested in child labor and education and my objective is to create
>>>>> variables for each children representing parents or household'
>>>>> characteristics.
>>>>> In particular, for each children I created two variables specifying the
>>>>> IDs of mother and father. Now I would like to create a  variable that, for
>>>>> each children, specifies parents' education in the following way
>>>>>
>>>>> motheredu_i=education[motherID_i]
>>>>>
>>>>> where education is a variable already in the dataset
>>>>>
>>>>> I know a way to do this, but it is extremely time consuming and I was
>>>>> wondering what would be the syntax to create the above "function".
>>>>>
>>>>> Thanks.
>>>>> *
>>>>> *   For searches and help try:
>>>>> *   http://www.stata.com/help.cgi?search
>>>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index