Announcement

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

  • Create a dummy variable in panel data based on an previous event

    Dear Statalisters


    I´m running an analysis of derivative use by mutual funds. I know the different fund holdings so that I can differ between derivative user funds and non derivative user funds via different dummies:

    - UserFund: 1 = if the fund uses derivatives at least once during the sample period, 0 = otherwise
    - User: 1 = if the fund uses derivatives in specific point of time, 0 = otherwise
    - Non Active User: 1 = if the actively decides not use derivatives in a specific point of time, 0 = otherwise

    At the moment I have all the three dummies implemented. But I´m afraid of a forward looking bias because if a user fund never have been used derivatives before you can´t really know whether the fund has made an active decision or not.

    To make it more clear I have prepared a short dataex sample to show you what I need:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long portfolioid int date float(UserFund User NonActiveUserFund) str1 FundName
    17705 15248 1 0 0 "A"
    17705 15340 1 1 0 "A"
    17705 15430 1 0 1 "A"
    17705 15521 1 0 1 "A"
    17705 15613 1 0 1 "A"
    17705 15705 1 1 0 "A"
    17707 15248 1 0 0 "B"
    17707 15340 1 0 0 "B"
    17707 15430 1 1 0 "B"
    17707 15521 1 0 1 "B"
    17707 15613 1 0 1 "B"
    17707 15705 1 0 1 "B"
    end
    format %td date
    As you can see, fund A and B are both UserFunds. On 31dec2001 (second time period) you see for the first time that fund A uses derivatives, and after that the manager should be able to actively decide to use derivatives or not.

    At the moment my NonActiveUserFund dummy equals 1 before 31dec2001, but it should be as mentioned above with the condition of first time use.

    How can I create a NonActiveUserFund dummy which equals only 1 after the condition, that he uses a derivative for one time, has been occured. (Should look like as in the dataex sample)


    I would be very pleased if you can help me with that.

    Many thanks in advance!


    Best Regards

    Jonas

  • #2
    Thanks for the sample data. Starting with that data, the following code seems to accomplish what you seek.
    Code:
    bysort FundName (date) : generate want = min(sum(User),1)
    replace want = 0 if User==1
    list, noobs sepby(FundName)
    Code:
    . list, noobs sepby(FundName)
    
      +---------------------------------------------------------------------+
      | portfo~d        date   UserFund   User   NonAct~d   FundName   want |
      |---------------------------------------------------------------------|
      |    17705   30sep2001          1      0          0          A      0 |
      |    17705   31dec2001          1      1          0          A      0 |
      |    17705   31mar2002          1      0          1          A      1 |
      |    17705   30jun2002          1      0          1          A      1 |
      |    17705   30sep2002          1      0          1          A      1 |
      |    17705   31dec2002          1      1          0          A      0 |
      |---------------------------------------------------------------------|
      |    17707   30sep2001          1      0          0          B      0 |
      |    17707   31dec2001          1      0          0          B      0 |
      |    17707   31mar2002          1      1          0          B      0 |
      |    17707   30jun2002          1      0          1          B      1 |
      |    17707   30sep2002          1      0          1          B      1 |
      |    17707   31dec2002          1      0          1          B      1 |
      +---------------------------------------------------------------------+

    Comment


    • #3
      Hey William!

      Thank you very much for your instant help, that worked very well

      Kind Regards

      Jonas

      Comment

      Working...
      X