Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: creating observations of non-occurrences


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: creating observations of non-occurrences
Date   Wed, 19 May 2010 17:32:51 +0200

<> 

This code can give you hints where to look:


*************
clear*
set obs 10
 
gen byte agentB=_n

tempfile first
save `first', replace

drop _all
set obs 10
gen byte agentA=_n
tempvar tosort
gen `tosort'=runiform()
sort `tosort'
drop `tosort'

merge 1:1 _n using `first', sorted nogen

expand _N, gen(original)
la def orig 0 "original" 1 "fake"
la val original orig

bys agentA agentB (original):  /* 
*/ replace agentB=cond(_n!=agentB[1],_n,  /* 
*/ agentB[1]+1) if _n!=1

l, sepby(agentA) h(20)

*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Frederick Guy
Gesendet: Mittwoch, 19. Mai 2010 16:32
An: statalist@hsphsun2.harvard.edu
Betreff: st: creating observations of non-occurrences

I have N observations, each of which records a transaction between an
agent of type A and an agent of type B. 

I want to create a dataset of 11*N observations: the N that I already
have, plus 10*N for AB pairs that did not transact.

More specifically, for each transaction AiBj, i = 1....N, j= 1....T, I
want to draw a random sample of 10 AiBk non-occurrences, from the T-1
cases of k != j.

As usual I expect that this is laughingly simple, but these loops are
new to me.

Thanks.

Frederick



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index