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]
Re: st: plotting a regression function with time-dummies indicating structural breaks
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: plotting a regression function with time-dummies indicating structural breaks
Date
Tue, 3 May 2011 11:20:06 +0100
I guess wildly that the problem you got is a variant of the "feature"
I mentioned earlier. -twoway function- is just using those
observations for which d1 == d1[1] & d2 == d2[1].
Either way, some kind of artefact is not surprising. As I emphasised
earlier, -twoway function- regards just one variable as
(independently) variable, namely what is plotted as x coordinate.
Nick
On Tue, May 3, 2011 at 10:53 AM, Oliver Jones
<[email protected]> wrote:
> Hi Nick,
> here is some example I just made up, that shows what I mean by "range
> problem"
>
> ************* begin example ****************
> clear
> set obs 20
>
> gen int TIME = _n + 1990
>
> * create dummies
> gen byte d1 = 0
> replace d1 = 1 if TIME > 1995
> gen byte d2 = 0
> replace d2 = 1 if TIME > 2005
>
> tsset TIME
>
> * set coefficients
> scalar b_0 = 100
> scalar b_1 = 2
> scalar b_2 = 10000
> scalar b_3 = -5
> scalar b_4 = 20
>
> * generate the time series
> set seed 1
> gen u = rnormal(0,2)
> gen y = b_0 + b_1*TIME + b_2*d1 + b_3*d1*TIME + b_4*d2 + u
>
> tw ///
> (tsline y) ///
> (function y = b_0 + b_1*x + b_2*d1 + b_3*d1*x + b_4*d2, ///
> range(1991 2010)), ///
> legend(order(1 "tsline" 2 "function"))
>
> ************* end example ****************
>
> I hope the resulting plot shows what I mean.
>
> Best
> Oliver
>
>
> Am 03.05.2011 11:29, schrieb Nick Cox:
>>
>> This is presumably a family of four curves given by a range on TIME_t
>> and Dummy_1 = 0, 1 and Dummy_2 = 0,1.
>>
>> -twoway function- will take care of TIME_t = x but it is completely
>> dumb about the dummies. My guess is that it will use Dummy_1[1] and
>> Dummy_2[1] and give you just one of the four depending on values in
>> the first observation.
>>
>> You will need to call -function- four times, but you don't need to
>> type the code four times.
>>
>> Something like this:
>>
>> forval a = 0/1 {
>> forval b = 0/1 {
>> local fcall `fcall' (function y = b_0 + b_1*x + `a'*(b_2 +
>> b_3*x) + b_4*`b', ///
>> range(TIME_t))
>> }
>> }
>>
>> twoway (tsline y) `fcall' , legend(order(2 "0 0" 3 "0 1" 4 "1 0" 5 "1 1"))
>>
>> I am assuming that this is generic code or that you have scalars b_0 ..
>> b_4.
>>
>> By the way, the -generate- line is irrelevant. -twoway function- works
>> with a generic x.
>>
>> On Tue, May 3, 2011 at 10:10 AM, Oliver Jones
>> <[email protected]> wrote:
>>
>>> I wonder if there is an easy way to plot a regression of the form:
>>>
>>> y_t = b_0 + b_1*TIME_t + Dummy_1*(b_2 + b_3*TIME_t) + b_4*Dummy_2
>>>
>>> So far I tried:
>>> gen x = TIME_t
>>> twoway ///
>>> (tsline y) ///
>>> (function y = b_0 + b_1*x + Dummy_1*(b_2 + b_3*x) + b_4*Dummy_2,
>>> ///
>>> range(`first_year' `last_year'))
>>>
>>> I seem to have a problem with the range, because the resulting graph just
>>> covers one third of the graph. But the shape seems to look ok, just
>>> compressed.
>>>
>>> Hopefully there is a nice way of plotting such stuff without the
>>> -function-
>>> command or some one has a hint regarding the range problem.
*
* 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/