Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: pairwise dummy variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: pairwise dummy variables
Date   Wed, 3 May 2006 13:06:57 +0100

Presumably you have done the combinatorial 
calculation that the number of variables 
implied is acceptable to Stata and your 
set-up. 

Something like this might be what you want: 

levelsof voter_id, local(voters)
tokenize "`voters'" 
local nv : word count `voters' 

forval i = 1/`nv' { 
	local I = `i' + 1 
	forval j = `I'/`nv' { 
		su vote if body_id == ``i'' & voter_id == ``j'', meanonly 
		gen byte vote_``i''``j'' = r(min) 
	}
}

You might need another underscore in the names 
to disambiguate. 

Nick 
[email protected] 

Serguei Kaniovski
 
> Thank you, but this is not quite what I need. I would like to compute 
> the frequencies of occurrence of all possible pairs of the binary 
> variable "vote". To begin with, for example, generate 
> variables "vote_*" 
> for each possible pair of "voters_id", such that that, e.g., 
> "vote_12" 
> takes the value "1" if "voters_id" both have "vote=1", else 
> zero, or NA 
> if one of the voters in not on the body.
> 
> body_id,voter_id,vote,vote_12,vote_13,vote_17,vote_19,vote_23,
> vote_27,vote_29,vote_37,vote_39,...
> 1,1,1,0,1,1,0,0,0,0,1,0
> 1,2,0,0,1,1,0,0,0,0,1,0
> 1,3,1,0,1,1,0,0,0,0,1,0
> 1,7,1,0,1,1,0,0,0,0,1,0
> 1,9,0,0,1,1,0,0,0,0,1,0
> 2,1,1,0,.,0,.,.,0,.,.,.
> 2,2,0,0,.,0,.,.,0,.,.,.
> 2,7,0,0,.,0,.,.,0,.,.,.
> 
> and so on.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index