Stata: If all observations unique, skip code -


i have dataset tells me how many referrals each general practitioner (gp) makes each hospital.

if @ least 1 gp in data refers patients 2 (or more) different hospitals, want run additional code, otherwise don't.

i using code:

set more off gsort gp -referrals code: gen nvals = _n ==1 generate obs = _n  if nvals != obs { display "different number of unique observations total observations-therefore run additional code here" continue } display "same number of unique observations total observations-therefore loop don't wish run additional code" 

at moment doesn't seem working.

could me develop code please? i.e. if total number of observations equal total number of unique observations, know can skip next section of code- go have:

display "different number of unique observations total observations-therefore run additional code here" 

a simple solution isid, combined capture. example, auto dataset uniquely identified make variable, can generate non-unique manufacturer variable illustrate idea:

sysuse auto , clear gen manufacturer = word(make, 1)  capture isid manufacturer if _rc != 0 di "observations manufacturer not unique" else if _rc == 0 di "observations manufacturer unique"  capture isid make if _rc != 0 di "observations make not unique" else if _rc == 0 di "observations make unique" 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -