Announcement

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

  • #16
    Everything is working perfectly for the export. I kept working at it yesterday and realised my error. You have confirmed it here. There are so many small things to remember, I guess it will just take time, practice and experience. Must stick at it!

    My code is now working fine from an export perspective:

    Code:
    putexcel H1=("F") I1=("DF1") J1=("DF2")
    loc row = 2
    foreach x of varlist wk3_zwei {
      forvalues id = 0/2 {   
        forvalues me = 0/2 { 
          regress `x' if MothersEthnicity==`me' & Infant_diplo==`id'
          putexcel H`row' = (e(F)) I`row' =  (e(df_m)) J`row' =  (e(df_r))
          loc row = `row' + 1
        }
      }
    }

    However, the values it is calculating for Sum of Squares (SS), Degrees of Freedom (DF) are zero and Mean of Squares (MS) is "."

    Is this because of the way that I have the syntax? In the non-macro version of what I am wanting to achieve, that doesnt include excel output, being:

    Code:
    sort Infant_diplo
    
    by Infant_diplo : oneway wk3_zwei MothersEthnicity_Nu , tabulate
    The results are fine.

    Should I be using a command other than regress in the macro?

    The full code I am now trying to run looks like:

    Code:
    putexcel set "FileName", sheet ("ANOVA")modify
    putexcel A1=("Variable") B1 = ("Mean") C1=("SD")
    local row = 2
    foreach x of varlist wk3_zwei {
      forvalues id = 0/2 {   
        forvalues me = 0/2 { 
          summarize `x' if MothersEthnicity==`me' & Infant_diplo==`id'
          putexcel A`row' = ("`x'") B`row' = (r(mean)) C`row' = (r(sd)) 
          loc row = `row' + 1
        }
      }
    }
    
    putexcel H1=("F") I1=("DF1") J1=("DF2")
    loc row = 2
    foreach x of varlist wk3_zwei {
      forvalues id = 0/2 {   
        forvalues me = 0/2 { 
          regress `x' if MothersEthnicity==`me' & Infant_diplo==`id'
          putexcel H`row' = (e(F)) I`row' =  (e(df_m)) J`row' =  (e(df_r))
          loc row = `row' + 1
        }
      }
    }

    The results for mean and standard deviation are the same in both the non-macro version of the code and the macro version which excludes the excel output. However the SS, DF and MS are not.

    Do you have any insights you wouldnt mind sharing?

    thanks as always,

    Mel

    Comment


    • #17
      Is there some reason you have
      Code:
            regress `x' if MothersEthnicity==`me' & Infant_diplo==`id'
      instead of the code I show in post #15
      Code:
            regress `x' i.MothersEthnicity_Nu if MothersEthnicity==`me' & Infant_diplo==`id'
      which I based on the code you show in post #8?

      Comment


      • #18
        Hi William, I had altered it as that was also delivering values of 0 for SS and Df and a "." for MS, so assumed that had been my error. Was trying different permeatations of the code to try and determine where I was going wrong...

        Running the code either way as you have displayed above still gives me the same error.

        Comment


        • #19
          I am sorry, I worked with your code from post #14 without thinking carefully about what it does. You should not loop over Mothers Ethnicity, because it is the independent variable in the regression.
          Code:
          putexcel H1=("F") I1=("DF1") J1=("DF2")
          loc row = 2
          foreach x of varlist wk3_zwei {
            forvalues id = 0/2 {   
              regress `x' i.MothersEthnicity_Nu if Infant_diplo==`id'
              putexcel H`row' = (e(F)) I`row' =  (e(df_m)) J`row' =  (e(df_r))
              loc row = `row' + 1
            }
          }

          Comment


          • #20
            Thank you William.

            The output I am now receiving from stata is:

            Wk 3 z-weight
            Dilpotype (Taster) 3 means and 3 SD (Chinese, Malay, Indian)


            Wk 3 z-weight
            Dilpotype (Non-taster ) 3 means and 3 SD (Chinese, Malay, Indian)


            Wk 3 z-weight
            Dilpotype (Heterzygous) 3 means and 3 SD (Chinese, Malay, Indian)

            and one set of one set of SS, DF MS

            However, to clarify, when you say above
            You should not loop over Mothers Ethnicity, because it is the independent variable in the regression.
            The independent variable in the analysis is the Wk3 weight and the dependent variables are Infant Diplotype and Mothers Ethnicity, as I am wanting to show:

            - the effect of having a particular diplotype (taster) on your weight status if you are chinese,
            - then the effect of having that same particular diplotype (taster) on your weight status if you are indian,
            - and lastly the effect of that same particular diplotype (taster) on your weight status if you are malay.

            Those three sets of results then get repeated for diplotype non-taster and diplotype heterozygous. Resulting in 9 means and standard deviations for the independent variable Wk3 Weight, which is outputting correctly per the first part of the code above.

            Am just wanting to clarify that with the syntax as it is written for the regress part of the code, am I achieving the output correctly? As you mention mothers ethnicity as the independ variable and just want to ensure.










            Comment


            • #21
              The independent variable in the analysis is the Wk3 weight and the dependent variables are Infant Diplotype and Mothers Ethnicity
              That is not the terminolgy I am used to, and not the terminology used by Stata. From help regress
              Code:
              Syntax
              
                      regress depvar [indepvars] [if] [in] [weight] [, options]
              The dependent variable - Wk3 weight in your regress command - is assumed to depend on the values of the independent variables - diplotype and ethnicity in your regress command - and those do not depend on any other variable in the model.

              Comment


              • #22
                Got you! Thanks again for all of your help on this William. I am certainly a work in progress as I said earlier. I have learnt a great deal from you in the last week or so. Truly appreciated.

                Regards
                Mel

                Comment

                Working...
                X