data management - Stata Deleting Multiple Observations -
i have next info matrix containing ideology scores in customized dataset:
year state cdnum party name dwnom1 1946 23 10 200 woodruff 0.43 1946 23 11 200 bradley f. 0.534 1946 23 11 200 potter c. 0.278 1946 23 12 200 bennett j. 0.189
my unit of analysis given congressional district, in given year. 1 can see state #23, cdnum #11, has 2 observations in 1946.
what delete before observation, in case observation corresponding name: bradley.f. happens when congressional district has 2 members in given congress. effort of code have tried follows:
drop if year==[_n+1] & statenum==[_n+1] & cdnum==[_n+1]
my effort conditional argument, drop observation if: year same next observation, statenum same next observation, , cdnum same next observation. in way, can insure each district has 1 corresponding given year. when effort run code get:
drop if year==[_n-1] & statenum==[_n-1] & cdnum==[_n-1] (0 observations deleted)
brief alternative: should check out duplicates
command.
detailed explanation of error:
you don't mean stata.
your conditions such
if year == [_n-1]
should
if year == year[_n-1]
and forth.
[_n-1]
by treated if typed
_n-1
which observation number, minus 1.
here dopey example. read in auto data.
. sysuse auto (1978 automobile data) . list foreign if foreign == [_n-1], nola +---------+ | foreign | |---------| 1. | 0 | +---------+
the variable foreign
equal _n - 1
exactly once, in observation 1 when foreign
0 , _n
1.
in short, [_n-1]
not interpreted previous value (of variable mentioned).
help subscripting
gives basic help.
stata data-management
No comments:
Post a Comment