In the dataex, JCS is always the extreme.
Now, re-running my code with #5, I notice that it does not handle the missing JCS properly. The following revision of the code does:
Code:
rename (house JCS senate pres) ideol= gen `c(obs_t)' obs_no = _n reshape long ideol, i(obs_no) j(inst) string drop if missing(ideol) by obs_no (ideol), sort: egen JCS_order = max(cond(inst == "JCS", _n, .)) by obs_no (ideol): gen SOPconstraint = 0 if !inlist(JCS_order, 1, _N) & !missing(JCS_order) by obs_no (ideol): replace SOPconstraint = ideol[2]-ideol[1] if JCS_order == 1 by obs_no (ideol): replace SOPconstraint = ideol[_N]-ideol[_N-1] if JCS_order == _N drop JCS_order reshape wide rename ideol* *
Code:
. clear* . graph use "C:\Users\clyde\Downloads\SOP constraint depicted.gph" . . // EXTRACT THE DATA FROM THE GRAPH . serset dir 0. 18196 observations on 5 variables pres JCS senate house year . serset set 0 . serset use . summ Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- pres | 17,550 .0299904 .4914045 -.504 .692 JCS | 16,290 .0416405 .148949 -.296214 .2412361 senate | 18,195 -.0269929 .0613419 -.131 .134 house | 18,195 -.0467056 .0552665 -.136 .117 year | 18,195 1967.219 19.84449 1925 1996 . . // CALCULATE THE SOP_constraint . rename (house JCS senate pres) ideol= . gen `c(obs_t)' obs_no = _n . . reshape long ideol, i(obs_no) j(inst) string (j = JCS house pres senate) Data Wide -> Long ----------------------------------------------------------------------------- Number of observations 18,196 -> 72,784 Number of variables 6 -> 4 j variable (4 values) -> inst xij variables: ideolJCS ideolhouse ... ideolsenate -> ideol ----------------------------------------------------------------------------- . drop if missing(ideol) (2,554 observations deleted) . . by obs_no (ideol), sort: egen JCS_order = max(cond(inst == "JCS", _n, .)) (5,070 missing values generated) . by obs_no (ideol): gen SOPconstraint = 0 if !inlist(JCS_order, 1, _N) & !missing(JCS_order) (29,310 missing values generated) . by obs_no (ideol): replace SOPconstraint = ideol[2]-ideol[1] if JCS_order == 1 (1320 real changes made) . by obs_no (ideol): replace SOPconstraint = ideol[_N]-ideol[_N-1] if JCS_order == _N (22920 real changes made) . drop JCS_order . . reshape wide (j = JCS house pres senate) Data Long -> Wide ----------------------------------------------------------------------------- Number of observations 70,230 -> 18,195 Number of variables 5 -> 7 j variable (4 values) inst -> (dropped) xij variables: ideol -> ideolJCS ideolhouse ... ideolsenate ----------------------------------------------------------------------------- . rename ideol* * . . . summ SOPconstraint Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- SOPconstra~t | 16,290 .0368904 .0599033 0 .2276687 . count if missing(JCS) 1,905 . count if missing(SOPconstraint) 1,905 .
Comment