Statalist


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

st: AW: Creating a variable: from monthly to annual


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Creating a variable: from monthly to annual
Date   Thu, 30 Apr 2009 15:48:28 +0200

<> 

Here is an example for Carlos...

*************
clear*
//10 years
set obs 10
gen year=_n
//expand to 12 months
expand 12
sort year
egen month=seq(), from(1) to(12)

//from http://www.stata-journal.com/sjpdf.html?articlenum=pr0013
//follow special sequences

//generate label for months
tokenize `c(Months)'

forvalues i = 1/12 {
 label def month `i' "``i''" , modify
 }
label val month month

//values
gen myvalue=rnormal(1000,1000)

//collapse it by year
preserve
	collapse (mean) myvalue, by(year)
	list, noobs
restore

//or put it in a graph
graph bar (mean) myvalue, over(year)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Carlos Garcia
Gesendet: Donnerstag, 30. April 2009 15:29
An: statalist@hsphsun2.harvard.edu
Betreff: st: Creating a variable: from monthly to annual

Dear statalist members:

I am running into a problem with a dataset that has observations by
month. I want to create an annual representation of the dataset (or
variable) with the average for the observations in each year.

May you please share me some ideas?

All suggestions will be highly appreciated.

Carlos García
LSU Student

*
*   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   |   What's new   |   Site index