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

st: RE: How to generate this variable please?

From   "Martin Weiss" <>
To   <>
Subject   st: RE: How to generate this variable please?
Date   Wed, 21 Oct 2009 23:52:00 +0200


Try this with no warranty :-)
I do have a feeling there is some command, like moving average or -rolling-,
that can make this a little more elegant...

set obs 51

gen year=_n+1949
expand 100

gen byte category=irecode(runiform(), /* 
 */ 0, .08, .16, .24, .32, .4, .48, /* 
 */  .54, .62, .68, .78, .89 )


capture erase info.dta
tempname hdle
postfile `hdle' year /* 
 */ category mean /* 
 */  using info

levelsof category, local(mycats)

qui forv y=1952/1998{
	foreach cat of local mycats{
		cou if inrange(year, `y'-3, `y'+3) & /* 
 		*/ category==`cat'
		post `hdle' (`y') (`cat') (`r(N)')

postclose `hdle'

u info, clear
gen lb=y-3
gen ub=y+3
order lb year ub /* 
 */  category mean

l,  noobs sepby(year) h(30)



-----Original Message-----
[] On Behalf Of Nirina F
Sent: Mittwoch, 21. Oktober 2009 23:05
Subject: st: How to generate this variable please?

Dear all,

I am not even sure how to search in the help for this so I thought I
would ask you.

I have two variables year (1950 to 2000) and field. Field has
different categories 1 for accounting, 2 for art 3 for biochemistry
etc....until 12.

I would like to have a variable that shows the mean of the frequency
in accounting (category 1) for year -3 and +3. To be more explicit:
for example, I studied in 1955. I would like to attribute to myself
the average frequency of people who did accounting between 1952 and
1958 so that it will be an indicator for me on how popular accounting
was around 1955. For year 1950, we can just look at +3, for year 2000,
we can just look at -3 years.
I am confused myself so I hope you understand what I mean.
then I would like to do it for category 5 and 6 together of variable Field.

Thank you so very much in advance for your help,
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index