[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Loop year variable
Nick Cox <firstname.lastname@example.org>
Re: st: Loop year variable
Sun, 21 Oct 2012 13:06:55 +0100
I gathered from your original posting that you had yearly data. I
understand that matches may be more frequent than yearly, but I can't
advise further without seeing what your data look like as the trade
data and match data are not obviously compatible.
On Sun, Oct 21, 2012 at 1:00 PM, emanuele mazzini
> Dear Mr Cox,
> thank you for your reply. The point, however, is that I cannot declare
> my dataset to be time-series (how would like but I cannot) due to the
> fact that some matches may take place once, twice or even more times
> in the same year. That is why I was looking form a manual command. I
> may better handle this first? And how can I do that in your opinion?
> Thanks in advance,
> 2012/10/21 Nick Cox <email@example.com>:
>> This should yield to a treatment in terms of spells in the sense of
>> -tsspell- (SSC) and of
>> SJ-7-2 dm0029 . . . . . . . . . . . . . . Speaking Stata: Identifying spells
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
>> Q2/07 SJ 7(2):249--265 (no commands)
>> shows how to handle spells with complete control over
>> spell specification
>> Look at -tsspell- first; it is self-contained. That is, your panels
>> are defined by country pairs (dyads) and the start of a spell is
>> defined by a match taking place (or a particular result; I don't
>> follow exactly what you want, e.g what about draws?). Then a variable
>> defined by -tsspell- gives you sequence in spell. You may need to
>> subtract 1.
>> I don't see that loops are needed.
>> On Sun, Oct 21, 2012 at 12:07 PM, emanuele mazzini
>> <firstname.lastname@example.org> wrote:
>>> I am not a new Stata user, but I have to admit I still encounter some
>>> problems with writing loops. A loop may not be the solution to the
>>> issue I am going to describe, but I thought it is tough.
>>> I do have a dataset where I have country-pair trade observations for
>>> years 1950-2006 as well as another information, which is football
>>> match result for some dyads. I therefore need to generate a variable
>>> that indicates how many years are passed since the last won/lost of a
>>> country versus another. Suppose FT_A and FT_B are the final results
>>> for team A and B. I thought to generate a variable as follows:
>>> gen int date_won=year if FT_A>FT_B | FT_A<FT_B
>>> in order to get a variable that is = year for every observation I have
>>> information about, which reports the year of the won/loss. I then
>>> thought to generate another variable (let's say yrs_won) to tell me
>>> how many years have gone by as follows:
>>> gen int yrs_won=year-date_won
>>> Unfortunately, I do not get what I want: the only value yrs_won
>>> assumes is 0, but for all years from 1983 until 2006 I would like it
>>> to be 1, 2,3 and so on.
>>> At the beginning I didn't realize the problem, now it may be occur due
>>> to the fact that date_won = year only for the year in which the match
>>> was played. I guess I need to do something such as writing a loop to
>>> let it spread over all cells of such variable, but I don't really know
>>> how to make it. Does anyone of you has any suggestion?
* For searches and help try: