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]

Re: st: Converting count to dichotomous variable


From   Eric Booth <eric.a.booth@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Converting count to dichotomous variable
Date   Fri, 9 Mar 2012 16:23:31 -0600


<>

Sorry, your mortalities were in var1, not var2, so the line:

bys day: egen var4_b = max(var2)

should have said:

bys day: egen var4_b = max(var1)

but the main point is the same.

EAB

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754




On Mar 9, 2012, at 3:57 PM, Eric Booth wrote:

<>

One strategy is to take the max number of mortalities (via -egen-) across all obs. in each day (or each pond/day -- I'm not sure which you need) and then recode anything greater than zero as a "1" indicating that mortalities occurred (leaving it as zero otherwise).  Here a quick example:


***************!
clear

*--fake data
set obs 7
g var3 = _n
expand 365
sort var3
g var2 = int(30+runiform()*100)
g var1 = int(runiform()*4)
su var*



**var4**
*--daily mortality
by var3:  g day = _n

*---1. for each pond/day
g var4_a = 1 if var1 != 0 //no mortalities each pond/day
replace var4_a = 0 if mi(var4_a)

*---2.  for each day only
bys day: egen var4_b = max(var2)
recode var4_b (1/max = 1) (0=0)

su var4*


***************!

- Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754


On Mar 9, 2012, at 3:30 PM, Aminu Shittu wrote:

Dear Statalisters,

I have var1 in my data set which represents number of death in a fish pond and var2 representing the existing number. The daily mortality was recorded in 7 fish ponds (var3) for a period of 1 year (365x7 rows). I am interested in creating a dichotomous var4, to indicate whether a daily mortality had occurred or not, without taking number of counts into consideration. Is it possible to do this in Stata or Excel?

Aminu.
*
*   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