Dear forum members,
my data is a panel structured as follows: id change nid1 nid2 nid3 nid4 nid5
For each id, i would like to create a variable that determines how many changes happened in the nids in the previous year. I tried:
egen nn_changes = count(change[_n-1]) if change[_n-1]==1, by( nid1 nid2 nid3 nid4 nid5) but it doesnt seem to work. Is a loop required here?
Your help is appreciated.
Kind regards
Related Posts with Counting observations of nearest neighbours
creating a loopHi guys: as you can see, below are four parts of repetitive codes, and the only difference is ccode2…
Fitting two lines using aaplotDear All, Is it possible to fit two lines (i.e. more than two variables) using the aaplot command? I…
Question: Generating summary statistics table with tabstat and tableDear all, I have recently attempted to generate a descriptive statistic table with the command Co…
Panel index within groupHey there, I like to create a new column indicating the occurrence of non-missing BAM within each id…
Time fixed effects as dummies change significanceDear Statalist, I am doing research on using nighttime light (radiances per area) to predict real re…
Subscribe to:
Post Comments (Atom)
0 Response to Counting observations of nearest neighbours
Post a Comment