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

st: reshape but with "overlapping entries"

From   "Ashim Kapoor" <>
Subject   st: reshape but with "overlapping entries"
Date   Mon, 24 Nov 2008 11:22:17 +0530

Hello everyone,

My data set is as following : -

Year - month     Production
Jan 2008              .1
Feb 2008              .2


So I write a code which marks out the 5 months with the MAXIMUM
production. That is easy. Next I want to see what happens 3 months
after the original 5 months of max production.

I do the above two as follows: --

sort production
gen marker=_n
replace marker=. if marker>5
replace marker=9 if marker~=.

forvalues x=1/3{
replace marker=1 if marker[_n-`x']==9 & marker~=9

( there are many other ways of doing this, I did this because I do not
want cascading of the marker )

So now the original 5 months are marked 9 and the following 3 months
are marked one.

I could drop the unmarker entries and RESHAPE my  dataset and I would
have what I want. BUT here is my problem.
there could be OVERLAPPING entries ruining my reshape. Let me explain.

I could have:-
Year-Month                     Marker
Jan-08                                9
Feb-08                                1
Mar-08                                1
Apr-08                                 1
May                                    9
Jun                                     9
July                                    1
Aug                                     1
Sept                                    1

Has anyone experienced this ? One way where I think I can work around
this is that I SAVE the dataset with marker~=. Then I keep only one
month marker 9 , it's following 3 months, reshape and save and append
all the reshaped lines in the end. IS there a better way of doing this

Thank you,
*   For searches and help try:

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