Announcement

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

  • What is wrong my code as posted here?

    There is two region dummy variables mi (mi takes the value 1 if Michigan and 0 otherwise) and 32 months in my panel dataset. To compare the coefficients in front of all month dummies in Michigan and other states, I write down the following codes:

    gen nonmi = 1 if mi==0
    replace nonmi = 0 if mi==1
    forvalues i = 1/32 {
    gen dmimonth`i' = mi*month if month == `i'
    gen dnonmimonth`i' = nonmi*month if month == `i'
    }

    Then when I summarize dmimonth* dnonmimonth*, there are no such variables generated. Would you mind helping me out? Many thanks! The dataset looks like the following:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(state month) float(smoke_rate2 mi) byte(hispanic married mrace3)
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 2
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 1 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 1 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 1 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 3
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 3
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 0 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    19 1 .16875 0 0 1 1
    end

  • #2

    Your code can be simplified to


    Code:
    forvalues i = 1/32 {
             gen dmimonth`i' = mi*month if month == `i'
    }
    I don't know why that does not work, nor even why you want it. What is clear is that there is no more information in the other variables you mention.

    I suggesting backing up and saying why you want these 65 extra variables that cannot be achieved through factor variable notation.

    Comment


    • #3
      in your example data, month is always equal to 1, and mi is always equal to 0 (and nonmi is always equal to 1); thus, although I do obtain new variables from your code, they are always equal to missing EXCEPT for
      Code:
      . su dmimonth1 dnonmimonth1
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
         dmimonth1 |        100           0           0          0          0
      dnonmimonth1 |        100           1           0          1          1

      Comment


      • #4
        As Rich Goldstein perhaps also implies, a variable that is mostly missing is useless for modelling purposes.

        Comment


        • #5
          Thank you very much!

          This is an exercise to practice to understand F-statistics in DID context: Restrict your sample to the 32 months prior to the tax hike in Michigan. Estimate a model with a Michigan dummy, month effects, race effects, age effects, education effects, parity effects and dummies for Hispanic and Married. Next, estimate separate monthly dummy variables for Michigan and the control states. Using the printout, do an F-test that the monthly dummy variables for Michigan differ from the time-series in the control states. What are the degrees of freedom of the f-test and what is a 95% critical value for this test. For the pre-treatment period, can you accept or reject the null hypothesis that the monthly dummies are the same in the treatment and control states?

          Variable Definition:
          1) MONTH: This is an index that equals 1 in the first month (September 1991) 2 in the second (October 1991), through month 56. Month 33 is the month the new tax went into effect (May of 1994).
          2) STATE: 2-digit state FIPS code. Michigan is state 26. SMOKED Dummy variable, =1 if a mother self-reported that she smoked during her pregnancy, =0 otherwise.
          3) MRACE3: 3 level variable, =1 if White mother wife, =2 if Black, =3 if other race.
          4) MEDUC6: 6-level variable for mother’s education: =1 if <9 years, =2 if 9-11 years, =3 if 12 years, =4 if 13-15 years, =5 if 16+ years, =6 if education was not reported.
          5) PARITY: 4-level variable for mother’s parity of birth. =1 if this is the first birth, =2 if the second birth, =3 if third birth, =4 if fourth or higher birth.
          6) HISPANIC: Dummy variable, =1 if mother is Hispanic, =0 otherwise.
          7) MARRIED: Dummy variable, =1 if mother is married, =0 otherwise.

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(state month smoked ageg mrace3 parity meduc6 married hispanic)
          19 4 0 3 1 2 3 1 1
          19 3 0 2 1 1 4 0 0
          19 2 0 4 1 2 5 1 0
          19 2 0 2 1 1 3 1 0
          19 2 0 1 2 1 1 0 0
          19 1 0 3 1 1 5 1 0
          19 3 0 4 1 2 3 1 0
          19 1 1 3 1 4 3 0 0
          19 1 1 3 1 1 4 0 0
          19 1 1 1 1 1 2 0 0
          19 1 0 4 1 2 4 1 0
          19 1 0 4 1 4 4 1 0
          19 1 0 2 1 3 2 0 0
          19 1 0 2 1 1 3 1 0
          19 1 1 3 1 2 4 0 0
          19 1 0 4 1 2 4 1 0
          19 1 1 2 1 1 2 0 0
          19 2 0 2 1 1 5 0 0
          19 1 0 3 1 1 4 1 0
          19 1 1 4 1 1 3 1 0
          19 1 0 3 1 2 4 1 0
          19 1 0 1 1 1 2 0 0
          19 2 0 3 2 3 3 0 0
          19 1 0 2 1 1 3 1 0
          19 2 1 1 1 1 2 0 1
          19 1 0 3 1 2 4 1 0
          19 1 0 3 1 1 4 1 0
          19 1 1 3 1 2 3 1 0
          19 2 0 1 1 1 2 0 0
          19 1 0 2 1 1 3 1 0
          19 1 0 1 1 1 2 0 0
          19 1 1 2 1 2 2 1 0
          19 1 1 2 1 2 3 1 0
          19 1 0 2 1 1 4 1 0
          19 3 0 2 1 1 4 1 0
          19 1 0 2 2 3 2 1 0
          19 1 0 4 1 1 3 1 0
          19 1 0 3 1 2 4 1 0
          19 1 0 1 1 1 2 0 0
          19 1 0 2 1 2 2 0 0
          19 1 1 1 1 1 2 0 0
          19 1 0 4 3 2 5 1 0
          19 1 0 2 1 1 3 1 0
          19 1 0 2 1 2 2 1 0
          19 1 0 2 1 1 4 0 0
          19 1 0 3 1 2 5 1 0
          19 1 0 1 1 1 1 0 0
          19 2 1 1 1 2 3 0 0
          19 2 1 1 1 1 2 0 0
          19 1 0 1 1 1 3 0 0
          19 2 1 5 1 3 3 0 0
          19 1 0 3 1 3 2 0 0
          19 1 0 3 1 4 4 1 0
          19 1 0 5 1 2 4 1 0
          19 1 0 4 1 4 5 1 0
          19 1 0 2 1 2 4 1 0
          19 2 1 2 1 1 3 0 0
          19 1 1 3 1 3 3 1 0
          19 1 0 5 1 2 3 1 0
          19 1 0 2 1 1 1 1 0
          19 2 0 3 1 3 3 1 0
          19 2 0 1 1 1 2 0 0
          19 1 0 4 1 4 3 1 0
          19 2 0 3 1 3 5 1 0
          19 1 0 4 1 4 4 1 0
          19 1 0 1 1 1 3 0 0
          19 2 1 5 1 3 3 1 0
          19 1 0 5 1 1 4 1 0
          19 2 1 2 1 1 1 0 0
          19 1 0 6 1 2 5 1 0
          19 1 0 4 1 3 3 1 0
          19 1 0 3 1 1 5 1 0
          19 1 0 5 1 2 3 1 0
          19 2 0 2 1 1 4 1 0
          19 2 0 5 1 2 5 1 0
          19 1 0 2 1 1 4 0 0
          19 1 1 2 1 3 4 0 0
          19 1 0 2 1 1 3 0 0
          19 2 1 3 1 3 2 0 0
          19 1 0 3 1 3 3 1 0
          19 1 0 2 2 1 4 0 0
          19 1 1 1 1 1 2 0 0
          19 1 0 3 1 3 3 1 0
          19 2 0 2 1 2 2 0 0
          19 1 1 2 1 3 2 0 0
          19 1 0 5 1 2 4 1 0
          19 1 0 4 3 4 6 1 0
          19 1 0 4 1 3 5 1 0
          19 2 1 2 1 1 3 0 0
          19 2 0 2 1 3 2 1 0
          19 1 0 1 1 1 2 0 0
          19 1 0 4 1 1 4 0 0
          19 1 0 3 1 2 4 1 0
          19 1 1 1 1 1 2 0 0
          19 1 0 4 1 4 4 1 0
          19 1 0 3 2 4 2 0 0
          19 1 0 3 1 1 3 1 0
          19 1 1 5 1 3 3 1 0
          19 1 0 4 1 4 4 1 0
          19 1 0 2 1 2 3 1 0
          end

          Comment


          • #6
            Sorry to turn unhelpful, but you've now made it clear that this is an assignment, so I feel bound by the advice in the FAQ not to comment further. #4 in https://www.statalist.org/forums/help#adviceextras is the documentation. Others may draw the line in different places.

            #2 and #4 in this thread already contain hints that remain pertinent, however.

            Comment


            • #7
              I see. Thank you!

              Comment

              Working...
              X