Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting U-shaped curves using predict and twoway

    I am trying to test for an inversed U-shaped patterns between R&D attainment discrepancy (which is the difference between the level of R&D exhibited by a focal organization i at time t-1 and the average industry R&D level at time t-2) and innovative performance at time t+1 (measured as the number of patents filed by the focal firm).
    To test for a U-shaped between R&D attainment discrepancy and innovative performance, I used a random-effects negative binomial model (supported by a Hausman test) including the direct (significant and positive) and the squared term (significant and negative) of my IV.

    To corroborate my findings I would like to graph the X-Y relationship over the relevant range of X, while holding other continuous variables at the sample means, and binary variables at 1. Is the following procedure correct?

    * Random-effects negative binomial regression for innovative performance
    xtnbreg F1Patent RDgap RDgapSquared RD1lag SPFnegative SPFpositive SL L1Altman L1GD IMPintensityPERCE RelDiv UnrelDiv L1LogtotAsset AGE IndGrowth RDav IndNIP IndPAT _Iyear*, re


    *Generating Linear predicion for F1Patent after xtnbreg
    predict F1Patenthat

    *Graphing the results
    twoway line F1Patenthat RDgap if _est_IPModel==1, sort //*(_est_IPModel==1 corresponds to e(sample))
    twoway qfitci F1Patenthat GapBEST if _est_IPModel==1, sort

    I think that I failed in holding the remaining covariates at their means and significant binary variables at 1.


    Many thanks in advance for your always precious help,


    Ambra

  • #2
    I am not an expert with twoway, so I am sure experts will be able to improve on this. Maybe this reply will catch the eye of one of them, who will be so appalled that they take the time to post better technique.

    Below I give a made-up example using Stata's built-in auto data and a logit regression, and I do not have a squared term as your model does. But the general idea is the following steps.
    1. Fit the model
    2. Reduce the dataset to a single observation
    3. Plug in values of the variables to be held constant
    4. Expand the number of observations
    5. Fill in the values of the variable you want to vary for your predictions
    6. Use predict to get the predicted values
    7. Use twoway connected to plot the predicted values against the variable you are varying
    In your case, in step 5, you will need to create both RDGap and RDGapSquared.

    Let me add that I'm sure it would be possible to write code that takes the results from summarize and plugs them in where I've just typed constant values, but this is a twoway tutorial, not a summarize tutorial.

    Try the code below as is, and see what the results are. Then use it as a basis for your task. Come back if you have questions. And let's hope someone reads this who knows better technique will take the time to teach it to us.

    Code:
    sysuse auto, clear
    keep foreign price mpg weight
    logit foreign price mpg weight
    summarize
    drop if _n>1
    drop foreign
    replace price=6165
    replace weight=3019
    expand 30
    replace mpg = _n+11
    list, clean
    predict pfor
    twoway connected pfor mpg

    Comment


    • #3
      Subsequently I have learned of the user-written command marginscontplot (published in Stata Journal 13-3), which might well do what you need. Look in the output of search marginscontplot for a link to information about the command.

      Comment

      Working...
      X