Bookmark and Share

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: Store interaction coefficients


From   Jorge Eduardo Pérez Pérez <jorge_perez@brown.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Store interaction coefficients
Date   Fri, 18 Oct 2013 11:32:13 -0400

This is very useful, thanks. I need to learn to use -margins- better.

Estrella could also use the -post- option of margins to store the coefficients.

The only disadvantage of this is that -margins- re estimates the
coefficients and standard errors, but in this case there is no need.




--------------------------------------------
Jorge Eduardo Pérez Pérez
Graduate Student
Department of Economics
Brown University


On Thu, Oct 17, 2013 at 4:17 PM, Nick Winter <njgwinter@gmail.com> wrote:
> -margins- and -marginsplot- are your friends here.  Same example:
>
> webuse nlswork
> reg ln_wage c.age#i.birth_yr c.tenure#i.birth_yr
>
> margins birth_yr, dydx(age)
> marginsplot
>
> Nick Winter
>
>
>
>
> On 10/17/2013 5:36 AM, Estrella Gomez wrote:
>>
>> Thanks a lot; very useful
>>
>> Best,
>> Estrella
>>
>> 2013/10/16 Jorge Eduardo Pérez Pérez <jorge_perez@brown.edu>:
>>>
>>> This code runs a regression with factor variable interactions and
>>> recovers the coefficients and standard errors to be plotted against
>>> the discrete interaction variable. You can use the same approach to
>>> recover coefficients for other variables and for multiple regressions
>>> and plot them in the same graph:
>>>
>>> clear
>>> webuse nlswork
>>> xtset idcode year
>>> * Factor variable regression
>>> reg ln_wage c.age#i.birth_yr c.tenure#i.birth_yr
>>> * Get the interaction variables and store in global vars
>>> fvexpand c.age#i.birth_yr
>>> glo vars=r(varlist)
>>> * Loop over them to get coefs and ses, store in variables b and se
>>> gen b=.
>>> gen se=.
>>> glo i=1
>>> foreach x in $vars {
>>> replace b=_b[`x'] in $i
>>> replace se=_se[`x'] in $i
>>> glo i=$i+1
>>> }
>>> * Get lower and upper limits for CI
>>> gen bu=b+1.96*se
>>> gen bl=b-1.96*se
>>> * Get birth year variable for x axis
>>> sum birth_yr, d
>>> gen birth_yr_x=_n+r(min)-1 if !mi(b)
>>> * Plot
>>> line b bu bl birth_yr_x
>>>
>>>
>>> Hope this helps,
>>> --------------------------------------------
>>> Jorge Eduardo Pérez Pérez
>>> Graduate Student
>>> Department of Economics
>>> Brown University
>>>
>>>
>>> On Wed, Oct 16, 2013 at 11:14 AM, Estrella Gomez
>>> <estrellastata@gmail.com> wrote:
>>>>
>>>> Hi
>>>>
>>>> I've done a regression with several interaction terms:
>>>>
>>>> reg lsynq c.ldist#i.year i.dhome#i.year i.dlang#i.year contig colony
>>>> i.cno i.ono i.year
>>>>
>>>>
>>>> I would like to make three separate graphs showing the ldist, dhome
>>>> and dlang coefficients on the y-axis and year on the horizontal axis;
>>>> however, I don't know how to store the coefficients coming from an
>>>> interaction.
>>>>
>>>> Would it also be possible to put into the same graph another set of
>>>> coefficient coming from another regression?
>>>>
>>>> Since I guess that the graphs will be volatile, I would also like to
>>>> do a scatter along with an mband for each series. How could I combine
>>>> these graphs?
>>>>
>>>> Thanks a lot,
>>>> Estrella
>>>> *
>>>> *   For searches and help try:
>>>> *   http://www.stata.com/help.cgi?search
>>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index