Bookmark and Share

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: AW: Transposing datasets


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Transposing datasets
Date   Mon, 2 Aug 2010 13:50:02 +0200

<> 



*************
clear*

inp gvkey str10	datadate mcap_sum
212782	30jun2005	4946.9
212782	31jul2005	5042.1
212782	31aug2005	5145
212782	30sep2005	5302.5
212782	31oct2005	5253.5
212782	30nov2005	5642.7
212782	31dec2005	6230  
212783	30jun2005	496.9
212783	31jul2005	502.1
212783	31aug2005	515
212783	30sep2005	530.5
212783	31oct2005	523.5
212783	30nov2005	562.7
212783	31dec2005	630  
end

li, noo sepby(gvkey)

reshape wide mcap, i(gvkey) j(datadate) string

foreach var of varlist mcap_sum*{
	ren `var' `=subinstr("`var'", "mcap_sum", "date_", 1)'
}

l

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



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Kaspar Dardas
Gesendet: Montag, 2. August 2010 13:37
An: [email protected]
Betreff: st: Transposing datasets

Hi guys,

I have a dataset with about 32000 observations, which is in long
format (see structure below). gvkey is the identifier for a firm
(about 600 different firms), datadate is the monthend value between
2002 and 2010, which of course repeats in the dataset (again, long
format) and mcap_sum is my observation, which is different for each
month and gvkey.

gvkey	datadate	mcap_sum
212782	30jun2005	4946.9
212782	31jul2005	5042.1
212782	31aug2005	5145
212782	30sep2005	5302.5
212782	31oct2005	5253.5
212782	30nov2005	5642.7
212782	31dec2005	6230
etc...

Well, I would like to transpose my dataset so it shows each month as a
variable and the observations are mcap_sums. My tries with reshape
failed miserably. (xpose wont work because I still want to keep
mcap_sum as an observation).. Does anybody has a suggestion to solve
this quickly?

gvkey    31dec2005   30nov2005   31oct2005
212782  6230              5642.7           5253.5   ...........


Best,

Kaspar
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index