Announcement

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

  • Establishing my data as a panel

    I am employing the synthetic control method to establish the effect on labor supply of an intervention on a community. My comparison unit is a synthesize control unit and is created using the synth command. For robustness I am running this analysis on a couple different dimensions of employment (unemployment claims rate, employment level) so I am performing the analysis on a few different data sets. My problem is in establishing my data as a panel. I understand what the problem is, but I do not know how to fix it.

    When I attempt xtset I get the error message:

    . xtset county date
    repeated time values within panel
    r(451);


    and it makes sense that I get this error message, but how do I rectify this in my dataset? Each county and date has several observations.

    This is a general question and am hoping to get an answer that will help me understand the intuition behind xtset. Attached is a capture of my dataset. My data spans January 2018-September 2020 and has observations for every industry and every county in the state of Alaska. Thank you for any help, I am sure my professor is tired of my emails.

    Click image for larger version

Name:	CaptureQCEW.PNG
Views:	1
Size:	105.5 KB
ID:	1600153

  • #2
    My data spans January 2018-September 2020 and has observations for every industry and every county in the state of Alaska
    This is the key fact about your data. When you -xtset panelvar timevar-, the combination of panelvar and timevar must together single out unique observations in the data. So the panel variable must be comprehensive enough that it completely defines the units for which observations get repeated over time. Your panel is not the county; it is the combination of industry and county.
    Code:
    egen panel = group(county INDUSTRYCODENAICS)
    xtset panel date
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


    Comment


    • #3
      Thank you Clyde! I will try -dataex- right now. I am looking forward to try your egen code.
      I am also working on an itsa analysis and having a similar problem. I have run the dataex command but am not sure which is the results window I paste my results in. Is it just this text box I am typing in? If so I have pasted for examination. Here the issue is that my date is regularly spaced, but does not have intervals of 1 however my time variable is monthly, not daily so I am perturbed.

      My code:
      itsa number_of_visits, trperiod(2020m7; 2020m8; 2020m9; 2020m10; 2020m11; 2020m12) treatid(1) single figure posttrend replace


      panel variable: unique (strongly balanced)
      time variable: date, 2020m3 to 2021m2
      delta: 1 month
      date is regularly spaced, but does not have intervals of 1
      r(198);



      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float unique long county byte month float(year date) long(dx_label dx_code) byte number_of_visits
      1 1  1 2021 732 51 1  .
      1 1  2 2021 733 51 1  .
      1 1  3 2020 722 51 1  .
      1 1  4 2020 723 51 1  .
      1 1  5 2020 724 51 1  .
      1 1  6 2020 725 51 1  .
      1 1  7 2020 726 51 1  .
      1 1  8 2020 727 51 1  .
      1 1  9 2020 728 51 1  .
      1 1 10 2020 729 51 1  .
      1 1 11 2020 730 51 1  1
      1 1 12 2020 731 51 1  .
      2 1  1 2021 732  4 2  1
      2 1  2 2021 733  4 2  4
      2 1  3 2020 722  4 2  1
      2 1  4 2020 723  4 2  .
      2 1  5 2020 724  4 2  .
      2 1  6 2020 725  4 2  .
      2 1  7 2020 726  4 2  .
      2 1  8 2020 727  4 2  .
      2 1  9 2020 728  4 2  .
      2 1 10 2020 729  4 2  .
      2 1 11 2020 730  4 2  .
      2 1 12 2020 731  4 2  .
      3 1  1 2021 732  5 3 25
      3 1  2 2021 733  5 3 11
      3 1  3 2020 722  5 3  5
      3 1  4 2020 723  5 3  8
      3 1  5 2020 724  5 3 13
      3 1  6 2020 725  5 3 16
      3 1  7 2020 726  5 3 16
      3 1  8 2020 727  5 3 14
      3 1  9 2020 728  5 3 14
      3 1 10 2020 729  5 3 12
      3 1 11 2020 730  5 3 13
      3 1 12 2020 731  5 3 19
      4 1  1 2021 732 34 4  1
      4 1  2 2021 733 34 4  3
      4 1  3 2020 722 34 4  1
      4 1  4 2020 723 34 4  4
      4 1  5 2020 724 34 4  4
      4 1  6 2020 725 34 4  4
      4 1  7 2020 726 34 4  3
      4 1  8 2020 727 34 4  4
      4 1  9 2020 728 34 4  2
      4 1 10 2020 729 34 4  2
      4 1 11 2020 730 34 4  2
      4 1 12 2020 731 34 4  2
      5 1  1 2021 732 17 5  1
      5 1  2 2021 733 17 5  2
      end
      format %tm date
      label values county county
      label def county 1 "SGY", modify
      label values month name
      label def name 1 "January", modify
      label def name 2 "February", modify
      label def name 3 "March", modify
      label def name 4 "April", modify
      label def name 5 "May", modify
      label def name 6 "June", modify
      label def name 7 "July", modify
      label def name 8 "August", modify
      label def name 9 "September", modify
      label def name 10 "October", modify
      label def name 11 "November", modify
      label def name 12 "December", modify
      label values dx_label dx_label
      label def dx_label 4 " Alcohol abuse, uncomplicated", modify
      label def dx_label 5 " Alcohol dependence, uncomplicated", modify
      label def dx_label 17 " Cocaine dependence, uncomplicated", modify
      label def dx_label 34 " Opioid dependence, uncomplicated", modify
      label def dx_label 51 " Vascular dementia with behavioral disturbance", modify
      label values dx_code dx_code
      label def dx_code 1 "F0151", modify
      label def dx_code 2 "F1010", modify
      label def dx_code 3 "F1020", modify
      label def dx_code 4 "F1120", modify
      label def dx_code 5 "F1420", modify
      Last edited by raniyah bakr; 28 Mar 2021, 00:08. Reason: edited to shorten data example

      Comment


      • #4
        You have used -dataex- correctly, thank you!

        Your data has no difficulty with -xtset-. From what you show, it appears that this error message is arising from -itsa-. -itsa- is not an official Stata command, and it is one that I have no experience with. So I can't really help you here. If I were forced to guess, I could imagine that while your data as a whole has intervals of 1 (month) in the date variable, the observations for which number_of_visits is not missing have many gaps, and perhaps -itsa- cannot work with that. But I'm just speculating here.

        The author of -itsa-, Ariel Linden is a member of this forum, and perhaps will comment.

        Comment


        • #5
          Yes, you are correct Clyde, I remedied this with *replace number_of_visits=0 if number_of_visits==.* and had success with -itsa-
          My prior unemployment dataset has been -xtset- successfully however the -synth- command halts because I have too many observations. I have not found a way to remedy this yet.
          Thanks again for your help.

          Comment


          • #6
            Glad you were able to move forward. I don't know the -synth- command, so I'm afraid I can't help you with that part of it.

            Comment

            Working...
            X