- * Example generated by -dataex-. To install: ssc install dataex
- clear
- input byte id int year str1 industry float x str6 name float fq_x byte result
- 1 2008 "A" 1 "Emma" 1 .
- 2 2008 "A" 1.2 "Emma" 1 .
- 8 2008 "A" 1.4 "LEO" 1 .
- 3 2008 "A" 1.5 "Lucy" 2 0
- 4 2008 "A" 1.8 "Jessie" 2 0
- 7 2008 "A" 1.6 "Jessie" 2 0
- 5 2008 "A" 2 "James" 3 0
- 6 2008 "A" 2.2 "Emma" 3 2
- 9 2008 "A" 2.5 "James" 3 0
- 10 2008 "A" 2.6 "Wilson" 4 0
- 11 2008 "A" 2.8 "Jessie" 4 0
- 15 2008 "A" 2.6 "James" 4 0
- 12 2008 "A" 3.7 "Lucy" 5 0
- 13 2008 "A" 3.5 "Wilson" 5 0
- 14 2008 "A" 3.3 "Jessie" 5 0
- 16 2008 "B" 1 "Emma" 1 .
- 17 2008 "B" 1.2 "Jessie" 1 .
- 23 2008 "B" 1.4 "James" 1 .
- 18 2008 "B" 1.5 "LEO" 2 0
- 19 2008 "B" 1.8 "James" 2 1
- 22 2008 "B" 1.6 "LEO" 2 0
- 20 2008 "B" 2 "Wilson" 3 0
- 21 2008 "B" 2.2 "Jessie" 3 1
- 24 2008 "B" 2.5 "Wilson" 3 0
- 25 2008 "B" 2.6 "Jessie" 4 1
- 26 2008 "B" 2.8 "Lucy" 4 0
- 30 2008 "B" 2.6 "LEO" 4 0
- 27 2008 "B" 3.7 "Wilson" 5 0
- 28 2008 "B" 3.5 "Jessie" 5 1
- 29 2008 "B" 3.3 "James" 5 1
- 31 2009 "A" 1 "Emma" 1 .
- 32 2009 "A" 1.2 "Jessie" 1 .
- 38 2009 "A" 1.4 "James" 1 .
- 33 2009 "A" 1.5 "LEO" 2 0
- 34 2009 "A" 1.8 "James" 2 1
- 37 2009 "A" 1.6 "LEO" 2 0
- 35 2009 "A" 2 "Wilson" 3 0
- 36 2009 "A" 2.2 "Jessie" 3 1
- 39 2009 "A" 2.5 "Wilson" 3 0
- 40 2009 "A" 2.6 "Jessie" 4 1
- 41 2009 "A" 2.8 "Lucy" 4 0
- 45 2009 "A" 2.6 "LEO" 4 0
- 42 2009 "A" 3.7 "Wilson" 5 0
- 43 2009 "A" 3.5 "Jessie" 5 1
- 44 2009 "A" 3.3 "James" 5 1
- 46 2009 "B" 1.2 "James" 1 .
- 47 2009 "B" 1.5 "Emma" 1 .
- 52 2009 "B" 1.4 "Jessie" 1 .
- 48 2009 "B" 1.8 "Jessie" 2 1
- 49 2009 "B" 2 "LEO" 2 0
- 51 2009 "B" 1.6 "Wilson" 2 0
- 50 2009 "B" 2.2 "James" 3 1
- 53 2009 "B" 2.5 "LEO" 3 0
- 54 2009 "B" 2.6 "James" 3 1
- 55 2009 "B" 2.8 "Wilson" 4 0
- 59 2009 "B" 2.7 "Jessie" 4 1
- 60 2009 "B" 3.2 "Wilson" 4 0
- 56 2009 "B" 3.7 "Jessie" 5 1
- 57 2009 "B" 3.5 "Lucy" 5 0
- 58 2009 "B" 3.3 "Wilson" 5 0
- end
- tempfile fq_x1_full fq_x1_contract
- preserve
- keep if fq_x==1
- save "`fq_x1_full'"
- contract year industry name if fq_x==1
- save "`fq_x1_contract'"
- restore
- drop if fq_x==1
- merge m:1 year industry name using "`fq_x1_contract'" ///
- , keep(master matched) nogenerate
- replace _freq = 0 if mi(_freq)
- append using "`fq_x1_full'"
- assert _freq == result
- sort year industry fq_x name
- bys year industry name (fq_x): gen W2 = sum(fq_x==1)
- bys year industry fq_x name: replace W2 = . if fq_x==1