Dear all
I'm working with three level nested data:
Individuals (childnum6), nested within...
Nuclear families (linked by nfamid), nested within...
Extended families (linked by efamid)
I'm trying to remove extended family fixed effects manually by de-meaning my variables with respect to extended family averages. Using a sample of my data to test my code, I notice that the coefficient I get when including extended family dummies as fixed effects is different to when I de-mean the variables. If anyone could tell me where I'm going wrong I would be very grateful (code and sample data below).
P.S. not sure if it's at all relevant but chmarried6, chage6, childnum6 are at the individual level, whereas chtotal6 and feduc are at the nuclear family level.
I'm working with three level nested data:
Individuals (childnum6), nested within...
Nuclear families (linked by nfamid), nested within...
Extended families (linked by efamid)
I'm trying to remove extended family fixed effects manually by de-meaning my variables with respect to extended family averages. Using a sample of my data to test my code, I notice that the coefficient I get when including extended family dummies as fixed effects is different to when I de-mean the variables. If anyone could tell me where I'm going wrong I would be very grateful (code and sample data below).
P.S. not sure if it's at all relevant but chmarried6, chage6, childnum6 are at the individual level, whereas chtotal6 and feduc are at the nuclear family level.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long efamid float(nfamid chmarried6 chtotal6) byte childnum6 float(chage6 feduc) 1200002 4 0 3 1 45 13 1200002 4 . 3 2 42 13 1200002 4 1 3 3 38 13 1200004 7 1 2 1 42 20 1200004 7 1 2 2 37 20 1200005 8 1 2 1 49 14 1200005 8 0 2 2 48 14 1200007 12 1 3 1 38 16 1200007 12 . 3 2 35 16 1200007 12 1 3 3 . 16 1200007 13 1 3 1 46 17 1200007 13 1 3 2 43 17 1200007 13 1 3 3 42 17 1200009 15 1 9 1 50 13 1200009 15 1 9 2 48 13 1200009 15 1 9 3 47 13 1200009 15 1 9 4 46 13 1200009 15 1 9 5 45 13 1200009 15 1 9 6 44 13 1200009 15 1 9 7 44 13 1200009 15 1 9 8 41 13 1200009 15 1 9 9 33 13 1200009 16 1 3 1 60 14 1200009 16 1 3 2 53 14 1200009 16 1 3 3 46 14 1200010 18 0 2 1 34 17 1200010 18 1 2 2 30 17 1200011 19 1 2 1 45 12 1200011 19 1 2 2 43 12 1200012 21 1 4 1 47 12 1200012 21 1 4 2 45 12 1200012 21 0 4 3 43 12 1200012 21 1 4 4 38 12 1200013 23 0 3 1 44 17 1200013 23 1 3 2 42 17 1200013 23 1 3 3 40 17 1200015 28 0 2 1 42 12 1200015 28 0 2 2 39 12 1200016 29 1 3 1 52 13 1200016 29 0 3 2 50 13 1200016 29 0 3 3 48 13 1200017 31 0 2 1 30 14 1200017 31 0 2 2 30 14 1200017 32 1 3 1 48 12 1200017 32 1 3 2 47 12 1200017 32 1 3 3 36 12 1200018 33 0 3 1 49 12 1200018 33 0 3 2 . 12 1200018 33 1 3 3 . 12 1200019 35 1 4 1 44 18 1200019 35 1 4 2 42 18 1200019 35 0 4 3 41 18 1200019 35 1 4 4 38 18 1200019 36 1 2 1 31 16 1200019 36 0 2 2 27 16 1200020 37 . 2 1 . 22 1200020 37 . 2 2 . 22 1200021 39 0 2 1 48 15 1200021 39 0 2 2 46 15 1200021 40 1 4 1 52 15 1200021 40 1 4 2 50 15 1200021 40 1 4 3 46 15 1200021 40 1 4 4 42 15 1200024 45 . 2 1 41 16 1200024 45 1 2 2 38 16 1200028 52 1 2 1 44 12 1200028 52 1 2 2 42 12 1200028 53 1 2 1 36 12 1200028 53 1 2 2 32 12 1200029 54 0 4 1 49 16 1200029 54 1 4 2 46 16 1200029 54 1 4 3 43 16 1200029 54 1 4 4 39 16 1200032 60 0 7 1 56 16 1200032 60 1 7 2 54 16 1200032 60 1 7 3 52 16 1200032 60 1 7 4 50 16 1200032 60 1 7 5 48 16 1200032 60 . 7 6 45 16 1200032 60 1 7 7 36 16 1200033 61 0 3 1 49 14 1200033 61 1 3 2 45 14 1200033 61 . 3 3 21 14 1200034 64 0 6 1 49 16 1200034 64 . 6 2 49 16 1200034 64 . 6 3 48 16 1200034 64 1 6 4 47 16 1200034 64 1 6 5 46 16 1200034 64 1 6 6 43 16 1200036 67 1 2 1 50 12 1200036 67 1 2 2 48 12 1200036 68 0 7 1 56 12 1200036 68 1 7 2 53 12 1200036 68 . 7 3 51 12 1200036 68 . 7 4 47 12 1200036 68 1 7 5 43 12 1200036 68 0 7 6 41 12 1200036 68 1 7 7 39 12 1200037 69 1 2 1 39 17 1200037 69 0 2 2 37 17 end
Code:
*Generating de-meaned variables bysort efamid: egen mean_chmarried6 = mean(chmarried6) gen d_chmarried6 = chmarried6 - mean_chmarried6 bysort efamid: egen mean_chtotal6 = mean(chtotal6) gen d_chtotal6 = chtotal6 - mean_chtotal6 bysort efamid: egen mean_childnum6 = mean(childnum6) gen d_childnum6 = childnum6 - mean_childnum6 bysort efamid: egen mean_chage6 = mean(chage6) gen d_chage6 = chage6 - mean_chage6 bysort efamid: egen mean_feduc = mean(feduc) gen d_feduc = feduc - mean_feduc *Running regression with extended family dummies reg chmarried6 chtotal6 childnum6 chage6 feduc i.efamid, cluster(nfamid) *Running regression with de-meaned variables reg d_chmarried6 d_chtotal6 d_childnum6 d_chage6 d_feduc, cluster(nfamid)
Comment