Announcement

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

  • Snyth Package and formatting Data

    Hello all,
    I am on my 4th day with +100 errors in code trying to run the synth programme. My current attempt has 3 columns. Exchange, where stock exchange names are listed. Date where the stata monthly date codes are given (Jan2014 - Dec2022) given by 648 to 755. And Return where the subsequent ratio i previously calculated is given each month for 7 different stock exchages. A short snippet is shown below.
    Exchange Return Date2 Date_formatted
    ISEQ 6.634e-09 2014m1 648
    ISEQ 7.461e-09 2014m2 649
    ISEQ 5.102e-09 2014m3 650
    ISEQ 8.522e-09 2014m4 651
    ISEQ 7.945e-09 2014m5 652
    ISEQ 2.309e-08 2014m6 653

    The ISEQ return, (not really return acc a liquidity ratio i calculated but for some reason i chose this as a header) is what i am interested in. I need to create a synthetic ISEQ from the other 7 control stock exchanges i have. It is driving me crazy. If anyone could provide any avenues to look at, or any advice on how best to format the data it would be much appreciated, I cant look at that cigsales example anymore!

  • #2
    did you xtset?

    do you have an id for each stock exchange?

    Comment


    • #3
      Hi George. appreciate the response. I have since assigned ids for each stock exchange and resultingly created a data column for each control exchange with just the data in the pre-treatment period with their respective exchange_id. I fear my issue may be in the shape of my added data. The current error i get is "control units: for at least one unit predictor outcome is missing for all periods specified.
      My xtset commmand follows: xtset exchange_id Date formatted, monthly.

      Below: is two snippets of my data.

      Exchange Return Date2 Date_formatted exchange_id control_exchange2 control_exchange3 control_exchange4 control_exchange5 control_exchange6 control_exchange7 control_exchange8 treatment outcome
      ISEQ 6.634e-09 2014m1 2014m1 1 1 6.63e-09
      ISEQ 7.461e-09 2014m2 2014m2 1 1 7.46e-09
      ISEQ 5.102e-09 2014m3 2014m3 1 1 5.10e-09
      ISEQ 8.522e-09 2014m4 2014m4 1 1 8.52e-09
      ISEQ 7.945e-09 2014m5 2014m5 1 1 7.94e-09
      ISEQ 2.309e-08 2014m6 2014m6 1 1 2.31e-08
      ISEQ 1.070e-08 2014m7 2014m7 1 1 1.07e-08
      ISEQ 7.970e-09 2014m8 2014m8 1 1 7.97e-09
      .
      .
      .
      .Exchange Return Date2 Date_formatted exchange_id control_exchange2 control_exchange3 control_exchange4 control_exchange5 control_exchange6 control_exchange7 control_exchange8 treatment outcome
      WB 2.449e-09 2022m9 2022m9 2 0
      WB 3.413e-09 2022m10 2022m10 2 0
      WB 3.930e-09 2022m11 2022m11 2 0
      WB 3.725e-09 2022m12 2022m12 2 0
      BM 1.417e-10 2014m1 2014m1 3 1.42e-10 0
      BM 1.284e-10 2014m2 2014m2 3 1.28e-10 0
      BM 1.193e-10 2014m3 2014m3 3 1.19e-10 0
      BM 8.861e-11 2014m4 2014m4 3 8.86e-11 0
      BM 8.879e-11 2014m5 2014m5 3 8.88e-11 0
      BM 9.366e-11 2014m6 2014m6 3 9.37e-11 0
      BM 7.597e-11 2014m7 2014m7 3 7.60e-11 0

      (Edit: Apologies, blank spaces did not copy in with snippet. but first snippet please find blank space between exchange_id until treatment. I fear the blank space is my issue ! )
      Last edited by Ryan David; 31 Jan 2024, 04:08.

      Comment


      • #4
        I'm not understanding the problem. What is Stata doing that you don't want it to do? Or, what's it not doing that you want it to do? So far you've not said what the actual error is. Or, your code that you've estimated.


        I need to see those things so I can help you. The error Stata is telling you and your code. By the way, the synth example is the go to because it offers useful examples for SCM... but that's fine, everyone's problem is user specific.

        Comment


        • #5
          My code follows after importing, setting directory, installing synth etc, :
          gen Date_formatted = monthly(Date2, "YM")

          gen exchange_id = .
          replace exchange_id = 1 if lower(Exchange) == "iseq"
          replace exchange_id = 2 if lower(Exchange) == "wb"
          replace exchange_id = 3 if lower(Exchange) == "bm"
          replace exchange_id = 4 if lower(Exchange) == "london"
          replace exchange_id = 5 if lower(Exchange) == "frankfurt"
          replace exchange_id = 6 if lower(Exchange) == "omx"
          replace exchange_id = 7 if lower(Exchange) == "warsaw"
          replace exchange_id = 8 if lower(Exchange) == "athens"

          gen control_exchange2 = Return if exchange_id == 2 & Date_formatted >= 647 & Date_formatted <= 698
          gen control_exchange3 = Return if exchange_id == 3 & Date_formatted >= 647 & Date_formatted <= 698
          gen control_exchange4 = Return if exchange_id == 4 & Date_formatted >= 647 & Date_formatted <= 698
          gen control_exchange5 = Return if exchange_id == 5 & Date_formatted >= 647 & Date_formatted <= 698
          gen control_exchange6 = Return if exchange_id == 6 & Date_formatted >= 647 & Date_formatted <= 698
          gen control_exchange7 = Return if exchange_id == 7 & Date_formatted >= 647 & Date_formatted <= 698
          gen control_exchange8 = Return if exchange_id == 8 & Date_formatted >= 647 & Date_formatted <= 698

          xtset exchange_id Date_formatted, monthly
          tsset exchange_id Date_formatted

          gen treatment = (exchange_id == 1 & Date_formatted >= 647 & Date_formatted <= 755)
          gen outcome = Return if exchange_id == 1 & Date_formatted >= 647 & Date_formatted <= 755
          br

          synth treatment Return (exchange_id(2)-exchange_id(3)), ///
          trunit(1) trperiod(698)



          Getting a standard error code r(198) , with message preceeding error: control units: for 1 of out 7 units missing obs for predictor Return in period 666 -ignored for averaging
          does not exist as a (numeric) variable in dataset.
          This "for 1 of out 7 units missing obs" style error is repeating in all current variations of how i try to change style of data layout. I have previously tried with your scul command but unsure if Lasso regression was neccesary and had similar issues when running code. I would like to apologize for my noviceness, appreciate the time you are taking to help.
          I cannot get a synth command to run is my issue.
          Last edited by Ryan David; 01 Feb 2024, 07:18.

          Comment


          • #6
            Why are you limiting the data to the pre-treatment period?

            Comment


            • #7
              Limiting to pre-treatment period was a trial that i thought would have made sense in the control_exchange variables as i wanted to ensure my control unit was only taken from the pre-treatment period. I still have had no luck having changed it to include all available data. Any recommendation. Typical error code remains: does not exist as a (numeric) variable in dataset or does not exist as a (numeric) variable in dataset.

              Comment


              • #8
                If anyone sees this, i have fixed my issues and have successfully ran synth command to compute a synthetic control unit. Now to test robustness, and do sensitivity analysis

                Comment

                Working...
                X