*! enlarge: 1 obs per group -> whole group. Stas Kolenikov, 03.2000, v.1.0
program define enlarge
   version 6
   syntax varname, BY(varlist)
   local wassort: sortedby
   sort `by' `varlist'
   cap by `by': assert `varlist'[1]~=.
   if _rc~=0 {
      di in red "Warning: there are groups with no observations on `varlist'."
   }
   cap by `by': assert `varlist'[2]==. | _N==1
   if _rc~=0 {
      di in red "There are groups with more than one observation on `varlist'"
      exit 9
   }
   qui by `by': replace `varlist'=`varlist'[1]
   if "`wassort'"~="" { sort `wassort' }
end