Announcement

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

  • Clear all command

    Good morning, I am now doing a do_file but I noticed that if I run the whole do file I get different(and wrong) results than if I instead run differently 2 parts divided by a clear all. Anyone knows why?
    this are my command:
    use "C:\Users\tomma\OneDrive\Desktop\s1_1.dta"
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\S9_1.dta", nogenerate
    preserve
    drop if age_y<5
    drop if educ>14
    drop if s9_1q1 !=1
    oneway educ s9_1q2, scheffe
    restore
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\s2_a.dta", nogenerate
    preserve
    drop if s2q5 != 2
    drop if s9_1q1 != 1
    drop if s2q10>14
    oneway s2q10 s9_1q2, scheffe
    restore
    preserve
    drop if s2q5 != 1
    drop if s9_1q1 != 1
    drop if s2q14>14
    oneway s2q14 s9_1q2, scheffe
    restore
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\s2_B.dta", nogenerate
    drop if s2q5 != 1
    drop if s9_1q1 != 1
    drop if s2q24 >14
    oneway s2q24 s9_1q2, scheffe
    clear all
    use "C:\Users\tomma\OneDrive\Desktop\s1_1.dta"
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\S9_1.dta", nogenerate
    drop if age_y<5
    drop if s9_1q1 != 1
    drop if educ>14
    preserve
    drop if sex!=1
    oneway educ s9_1q2, scheffe
    restore
    drop if sex != 2
    oneway educ s9_1q2, scheffe

    clear all
    *here is where I divide the 2 parts"
    use "C:\Users\tomma\OneDrive\Desktop\s1_1.dta"
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\S9_1.dta", nogenerate
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\S5_1_a.dta", nogenerate
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\S5_1_b.dta", nogenerate
    merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\s8_1.dta", nogenerate
    drop if s9_1q1 !=1
    drop if educ>14
    gen dummy_participation = 1 if s9_1q2 == 2
    replace dummy_participation = 0 if s9_1q2==1
    regr educ dummy_participation s5_1q2 s5_1q3
    regr educ dummy_participation s5_1q14 s5_1q15
    regr educ dummy_participation s8_1q3 s8_1q4



    Hope someone can help me. Thanks in advance

  • #2
    I'm willing to bet my next 10 paychecks at both my jobs
    Code:
    merge m:m
    is not what you want. Either way, this question is super vague. Using Statalist is just like making wild mushroom risotto. If I asked you to make my favorite version of risotto, you'd likely need to know what the SPECIFIC ingredients are and the steps you do to make said dish. So far you've given the recipe (the code), but not the ingredients (the data).
    Precisely, you must give your dataset using dataex and your code that you've tried (formatted accordingly). No dataset, no code=no real assistance. Present your dataset (and your code!!!) in
    Code:
    
    Code delimiters
    Read the FAQ for more. Welcome to Statalist, Tommaso.

    Comment


    • #3
      Tommaso, welcome to the Stata Forum! You are not the first new to this list who did not read StataForum's FAQ (especially section 12) before posting their first question. However, I strongly recommend to do so. For example, you should put commands that you want to show us into code tags by toggling to the advanced editor and invoking the button with the # symbol.

      I can't answer your question but I noticed some inefficient code. For example, the first part can be simplified to
      Code:
      use "C:\Users\tomma\OneDrive\Desktop\s1_1.dta"
      merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\S9_1.dta", nogenerate
      oneway educ s9_1q2 if age_y < 5 & educ > 14 & s9_1q1 != 1, scheffe
      oneway educ s9_1q2 if age_y < 5 & educ > 14 & s9_q1q != 1 & sex != 1, scheffe
      oneway educ s9_1q2 if age_y < 5 & educ > 14 & s9_q1q != 1 & sex != 2, scheffe
      
      merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\s2_a.dta", nogenerate
      oneway s2q10 s9_1q2 if s2q5 != 2 & s9_1q1 != 1 & s2q10 > 14, scheffe
      oneway s2q14 s9_1q2 if s2q5 != 1 & s9_1q1 != 1 & s2q14 > 14, scheffe
      
      merge m:m hhcode using "C:\Users\tomma\OneDrive\Desktop\s2_B.dta", nogenerate
      oneway s2q24 s9_1q2 if s2q5 != 1 & s9_1q1 != 1 & s2q24 > 14, scheffe
      However, I am not sure that you really want to use merge m:m and I recommend to read the user manual [D] "Data Management", especially page 650. I also wonder whether invoking the merge-command sequentially really does what you intend to do.
      Last edited by Dirk Enzmann; 10 Jul 2022, 05:53.

      Comment


      • #4
        To add on to the above, this is from the Book of Data Management, Chapter D, verse/page 648. And, thus sayeth StataCorp:
        Because m:m merges are such a bad idea, we are not going to show you an example. If you think that you need an m:m merge, then you probably need to work with your data so that you can use a 1:m or m:1 merge.
        The solution, as Dirk notes, is joinby, the real m to m merge.

        But, we don't know if this is the solution, since we've not seen a data example yet, so all this this far is speculation.

        Comment

        Working...
        X