I'm afraid I can't help you. I can't reproduce your problem with my Stata. The code I gave earlier runs fine with the new example data, with no error messages, and it produces results at the end that look believable:
I can only assume that you have somehow changed the code from what was originally written. I suggest you scrap what you have and do a fresh copy/paste from #10 into a do-file and try again.
Code:
. // SAVE THE DATA FOR LATER USE
. tempfile holding
. save `holding'
file C:\Users\CLYDES~1\AppData\Local\Temp\ST_0h000001.tmp saved
.
. // SPLIT OUT THE CONTROL GROUP IDs INTO A SEPARATE
. // FILE OF CONTROL IDS SORTED IN RANDOM ORDER
. keep if survey == 0
(333 observations deleted)
. keep ID
. duplicates drop
Duplicates in terms of all variables
(655 observations deleted)
. set seed 1234
. gen double shuffle = runiform()
. sort shuffle
. rename ID ID0
. tempfile control_ids
. save `control_ids'
file C:\Users\CLYDES~1\AppData\Local\Temp\ST_0h000002.tmp saved
.
. // NOW CREATE A FILE OF CASE IDs
. use `holding', clear
. keep if survey == 1
(667 observations deleted)
. keep ID
. rename ID ID1
. duplicates drop
Duplicates in terms of all variables
(327 observations deleted)
.
. // CREATE MATCHED PAIRS
. merge 1:1 _n using `control_ids', keep(match) nogenerate
Result # of obs.
-----------------------------------------
not matched 0
matched 6
-----------------------------------------
. isid ID0
. isid ID1, sort
(data now sorted by ID1)
. gen long pair = _n
.
. // GO TO LONG LAYOUT AND BRING BACK THE OTHER VARIABLES
. reshape long ID, i(pair) j(_j)
(note: j = 0 1)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 6 -> 12
Number of variables 4 -> 4
j variable (2 values) -> _j
xij variables:
ID0 ID1 -> ID
-----------------------------------------------------------------------------
. merge 1:m ID using `holding', keep(match) nogenerate
Result # of obs.
-----------------------------------------
not matched 0
matched 669
-----------------------------------------
. assert survey == _j
. drop _j
.
. // PREPARE PRE-POST VARIABLE
. // BEGIN BY APPLYING CASE SURVEY DATE TO MATCHED CONTROL
. by pair (survey_date), sort: assert survey_date == survey_date[1] if !missing(survey_date)
. by pair (survey_date): replace survey_date = survey_date[1]
(336 real changes made)
. gen byte pre_post = (date >= survey_date)
.
. // DID ANALYSIS
. xtset ID
panel variable: ID (unbalanced)
. xtreg consumption i.survey##i.pre_post, fe vce(cluster pair)
note: 1.survey omitted because of collinearity
Fixed-effects (within) regression Number of obs = 669
Group variable: ID Number of groups = 12
R-sq: within = 0.0184 Obs per group: min = 52
between = 0.2156 avg = 55.8
overall = 0.0130 max = 57
F(2,5) = 2.57
corr(u_i, Xb) = -0.2708 Prob > F = 0.1706
(Std. Err. adjusted for 6 clusters in pair)
---------------------------------------------------------------------------------
| Robust
consumption | Coef. Std. Err. t P>|t| [95% Conf. Interval]
----------------+----------------------------------------------------------------
1.survey | 0 (omitted)
1.pre_post | 30.08198 52.27459 0.58 0.590 -104.2941 164.4581
|
survey#pre_post |
1 1 | -255.2466 112.8719 -2.26 0.073 -545.3931 34.89981
|
_cons | 1109.229 17.18425 64.55 0.000 1065.056 1153.403
----------------+----------------------------------------------------------------
sigma_u | 650.7295
sigma_e | 499.10863
rho | .62960918 (fraction of variance due to u_i)
---------------------------------------------------------------------------------

Comment