Announcement

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

  • Problem in panel data analysis regarding use of if clause

    Hello together,

    I am using Stata 16.1 and only had basic training with regressions and so on.
    Now I have to do a panel data analysis and try to rebuild a model used in a paper.

    In this model an instrumental variable (SSO) signifying an event is introduced that should be 1 if one of my variables (V1) is lower than the average of said variable (AV1). To be precise it must be lower than AV1 minus 2 standard deviations (SDV1) of V1.
    This I was able to rebuild with:
    replace SSO=1 if V1< AV1-2*SDV1
    But now the paper states, that the event should start (meaning SSO=1) as soon as V1 gets below AV1 minus one SD and end as soon as it reaches that threshold again.
    So I need to have a command look at the situation “around” my previously determined points of time at which SSO=1
    I thought I could use
    replace SSO=1 if F1.SSO=1 & V1<AV1-SDV1
    replace SSO=1 if L1.SSO=1 & V1<AV1-SDV1
    this way I would get all the points right before and after the event and if I would do that again with
    replace SSO=1 if F1.SSO=1 & V1<AV1-SDV1 for several times, until no real changes happen, I should be able to catch all of the points I want to have.

    However this doesn’t seem to work and I suspected that I couldn’t use “if” and base it on the same variable so I tried gen SSOO=SSO and thought I could work around that problem like this but Stata still won’t let me do it, returning “invalid syntax r(198);”
    I suspect that I cant used the F1,L1 with if but I have no idea on how to get the result I want. Do you have any ideas? I don’t seem to be able to exactly define what I want in 1 sentence, which is why I can’t find the answer I need, which is certainly buried in an answer somewhere already. Sorry for that.
    Below you can find an example I created with dataex, I hope this helps you help me. Thank you in advance!

    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(country time) float(V2 V1 AV1 SDV1 SSO)
    1 114 . . -626284992 541678912 0
    1 115 . . -626284992 541678912 0
    1 116 . . -626284992 541678912 0
    1 117 . . -626284992 541678912 0
    1 118 . . -626284992 541678912 0
    1 119 . . -626284992 541678912 0
    1 120 -16836188160 . -626284992 541678912 0
    1 121 -18236448768 -1400260608 -626284992 541678912 0
    1 122 -19536486400 -1300037632 -626284992 541678912 0
    1 123 -21409628160 -1873141760 -626284992 541678912 1
    1 124 -22782924800 -1373296640 -626284992 541678912 0
    1 125 -24309022720 -1526097920 -626284992 541678912 0
    1 126 -25717108736 -1408086016 -626284992 541678912 0
    Last edited by Erik Lodes; 20 Nov 2023, 07:30.
Working...
X