/******************************************************************** link2.do Written by Russell Dimond 10/2002 for Intermediate Stata Class Uses the map created in part one to link a person's data with their mother's data. ********************************************************************/ clear capture log close set more off log using link2,text replace use link gen id=mother sort id merge id using map /* Note that we are merging an observation with that observation's mother from the map! Thus obsNum is the mother's obsNum. */ drop if _merge==2 /* _merge==2 means observations from map that weren't matched with a person from the original data because their mother isn't in the data set. Thus they are duplicates. */ sort person ren obsNum momsObsNum label var momsObsNum "Observation number of Mother when sorted by person" drop id _merge gen diff=age[momsObsNum]-age save link2,replace log close