Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE:
From
HAKAN USLU <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE:
Date
Mon, 19 Aug 2013 18:53:28 +0000
> Hello all,
> I am having a problem with -collapse (count)-
> Can someone help me to convert (collapsing and counting) my data as
> follows? ;
>
> My data looks like this:
> year month type
> 2010 1 a
> 2010 1 a
> 2010 1 b
> 2011 1 b
> 2012 3 b
> 2010 1 c
> 2011 4 c
> 2011 4 c
> 2011 4 c
> 2010 2 c
> 2012 5 c
> 2012 5 c
>
> I need data that looks like this:
>
> year month a b c
> 2010 1 2 1 1
> 2010 2 0 0 1
> 2011 1 0 1 0
> 2011 4 0 0 3
> 2012 3 0 0 0
> 2012 5 0 0 2
>
>
> Basically, I try to collapse and count my data with respect to month
> and year. I have 800 different numeric characters in the variable
> namely 'type'. I want to convert each character to a new variable. I
> use Stata 11.0. I already tried the following loop but I got unexpected
> error message like 'type mismatch' or 'no observations'.
>
> foreach c in 1/800 {
> preserve
> keep if type == `c'
> collapse (count) type, by (month year)
> ren type `c'
> save `c', replace
> restore
> }
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/