stata - Compare each obs with rest of its sub-group -



stata - Compare each obs with rest of its sub-group -

i have next goal regarding info structure

group; month; year; next_year 1; february; 2014; 0 1; march; 2006; 0 1; november; 2013; 1 2; january; 2014; 0 3; january; 2004; 0

i have group, month , year, column next_year needs generated first three: each observation, want check if there observation within same grouping has date-value falls period of next year. if so, want set value of next_year 1, otherwise 0 (see example).

i started converting date format stata can interpret - using ym(month, year) - such can create comparisons. however, not sure how iterate on observations within grouping in order determine if case or not.

i know how in e.g. java, don't stata. suppose should not start loops there implemented commands such problems.

if want check if there next observation within next 12 months, can try:

clear set more off *----- illustration info ----- input grouping str8 month year 1 march 2006 1 march 2013 1 nov 2013 1 jan 2013 2 jan 2014 3 jan 2004 end *----- want ----- gen dat = monthly(month + string(year), "my") format dat %tm bysort grouping (dat): gen next = dat[_n+1] - dat <= 12 list, sepby(group)

make sure understand difference between nick's code , mine. work under different assumptions. can check differences running both pieces of code info have provided (originally nick's 1 observation deleted point across; chance, if utilize nick's info without modification, results same).

stata

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -