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: Merge Files one to many


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: Merge Files one to many
Date   Sat, 31 Mar 2012 19:31:12 -0500

<>


Since there is one principal observation per school & many teachers per school, you want a many-to-one merge with the teacher dataset in memory (assuming you've got Stata 12 since you didn't state otherwise --  you want to use the m:1 merge type).

That is, if you use the teacher dataset (the first dataset) as the master dataset (in memory) and merge in the principal dataset (the second dataset) as the 'using' dataset, then you'd run something like:

****
use "teacher.dta", clear 

merge m:1  schoolid using "principal.dta"  //include any options here about updating, replacing, or matching values

sa "combined.dta", replace
*check your merge report or run -tabulate _merge-
****

- Eric
__
Eric A. Booth
Public Policy Research Institute 
Texas A&M University
[email protected]
+979.845.6754




On Mar 31, 2012, at 7:00 PM, <[email protected]> wrote:

> Have two data sets with common variable. The teacher data set has several
> teachers per school. The school variable is a nominal variable that is
> unique to each school. So if there are 20 teachers in a school the school
> variable is repeated 20 times. The principal data file has one principal per
> school and I want to merge/match on school. There is one principal to each
> school and this file uses the same school variable to identify the school
> the principal is in. What I need to do is to match the principal data to
> every teacher in that school. 
> 
> So the file would look like:
> 
> 
> School	teacher_var1	teacher_var2	principal_var1
> 123		23			45			56	
> 123		25			44			56
> 123		21			43			56
> 123		56			55			56
> 331		21			22			51
> 331		21			29			51
> 331		26			21			51
> 
> Help please
> 		
> 
> *
> *   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/


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