Announcement

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

  • #16
    Originally posted by Andrew Musau View Post
    This is not tested and requires frames (Stata 16+).

    Code:
    local predictors_all_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.mom_child_loss_categorical i.mom_cohort
    local predictors_married_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth c.pop_age c.pop_age#c.pop_age i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.pop_edattain2 i.pop_edattain3 i.pop_edattain4 i.mom_cohort i.mom_child_loss_categorical
    levelsof sample, local(samples)
    frame create results
    frame results{
    set obs `=wordcount("`samples'")'
    gen sample=.
    gen all=.
    gen married=.
    }
    local i 0
    foreach sample of local samples{
    local ++i
    regress mom_fertility i.FirstDaughter `predictors_all_moms' if `sample'== sample [pweight=mom_perwt]
    frame results: replace sample= `sample' in `i'
    frame results: replace all= `=_b[1.FirstDaughter]' in `i'
    regress mom_fertility i.FirstDaughter `predictors_married_moms' if `sample'== sample [pweight=mom_perwt]
    frame results: replace married= `=_b[1.FirstDaughter]' in `i'
    }
    frame change results
    export excel using myfile, replace firstrow(variables)

    If you provide a dataex of the sample variable, I can have the output with variable labels instead of their values, e.g., "Bolivia" instead of its numeric code.


    How could I do what you proposed? I tried (see the commands in bold):

    Code:
     
     local predictors_all_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.mom_child_loss_categorical i.mom_cohort local predictors_married_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth c.pop_age c.pop_age#c.pop_age i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.pop_edattain2 i.pop_edattain3 i.pop_edattain4 i.mom_cohort i.mom_child_loss_categorical levelsof sample, local(samples) local sample_labels: value label sample frame create results frame results{     set obs `=wordcount("`samples'")'     gen sample=.     gen all=.     gen married=. } local i 0 foreach sample of local samples{     local ++i     local vl: label `sample_labels' `sample'     regress mom_fertility i.FirstDaughter `predictors_all_moms' if `sample'== sample [pweight=mom_perwt]     frame results: replace sample= `vl' in `i' (instead of frame results: replace sample= `sample' in `i')     frame results: replace all= `=_b[1.FirstDaughter]' in `i'     regress mom_fertility i.FirstDaughter `predictors_married_moms' if `sample'== sample [pweight=mom_perwt]     frame results: replace married= `=_b[1.FirstDaughter]' in `i' } frame change results export excel using myfile, replace firstrow(variables)
    But I get the error message: Bangladesh not found. (Bangladesh is the label of the first sample.)

    Comment


    • #17
      Great. To get the value labels outputted, add the following lines:

      Code:
      local predictors_all_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.mom_child_loss_categorical i.mom_cohort
      local predictors_married_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth c.pop_age c.pop_age#c.pop_age i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.pop_edattain2 i.pop_edattain3 i.pop_edattain4 i.mom_cohort i.mom_child_loss_categorical
      levelsof sample, local(samples)
      frame create results
      frame results{
          set obs `=wordcount("`samples'")'
          gen sample=.
          gen label=""
          gen all=.
          gen married=.
      }
      local i 0
      foreach sample of local samples{
          local ++i
          regress mom_fertility i.FirstDaughter `predictors_all_moms' if `sample'== sample [pweight=mom_perwt]
          frame results: replace sample= `sample' in `i'
          frame results: replace label="`:lab (sample) `i''" in `i'
          frame results: replace all= `=_b[1.FirstDaughter]' in `i'
          regress mom_fertility i.FirstDaughter `predictors_married_moms' if `sample'== sample [pweight=mom_perwt]
          frame results: replace married= `=_b[1.FirstDaughter]' in `i'
      }
      frame change results
      export excel using myfile, replace firstrow(variables)

      Comment


      • #18
        Originally posted by Andrew Musau View Post
        Great. To get the value labels outputted, add the following lines:

        Code:
        local predictors_all_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.mom_child_loss_categorical i.mom_cohort
        local predictors_married_moms c.mom_age c.mom_age#c.mom_age c.mom_age_at_birth c.pop_age c.pop_age#c.pop_age i.mom_edattain2 i.mom_edattain3 i.mom_edattain4 i.pop_edattain2 i.pop_edattain3 i.pop_edattain4 i.mom_cohort i.mom_child_loss_categorical
        levelsof sample, local(samples)
        frame create results
        frame results{
        set obs `=wordcount("`samples'")'
        gen sample=.
         gen label=""
        gen all=.
        gen married=.
        }
        local i 0
        foreach sample of local samples{
        local ++i
        regress mom_fertility i.FirstDaughter `predictors_all_moms' if `sample'== sample [pweight=mom_perwt]
        frame results: replace sample= `sample' in `i'
        frame results: replace label="`:lab (sample) `i''" in `i'
        frame results: replace all= `=_b[1.FirstDaughter]' in `i'
        regress mom_fertility i.FirstDaughter `predictors_married_moms' if `sample'== sample [pweight=mom_perwt]
        frame results: replace married= `=_b[1.FirstDaughter]' in `i'
        }
        frame change results
        export excel using myfile, replace firstrow(variables)
        Dear Andrew,
        instead of the labels of the variable sample, I get the value of i in the column label, for example 1, 2, 3, 4, 5, ...
        What could be wrong? I am trying to find out, though unsuccessfully.
        Thank you

        Comment


        • #19
          You are correct. I shouldn't be referencing \(i\) but \(sample\). Change the line

          frame results: replace label="`:lab (sample) `i''" in `i'

          to

          Code:
          frame results: replace label="`:lab (sample) `sample''" in `i'

          Comment


          • #20
            it works .. Thank you very much !!

            Comment


            • #21
              Originally posted by Veronika Valcikova View Post

              Dear Andrew,
              instead of the labels of the variable sample, I get the value of i in the column label, for example 1, 2, 3, 4, 5, ...
              What could be wrong? I am trying to find out, though unsuccessfully.
              Thank you
              Also, I would like to add significance stars for each coefficient ... how could I achieve this?

              Comment


              • #22
                This thread has gotten too long and out of topic. Start a new thread appropriately titled, including a reproducible example.

                Comment


                • #23
                  Originally posted by Andrew Musau View Post
                  This thread has gotten too long and out of topic. Start a new thread appropriately titled, including a reproducible example.
                  of course, will do so! Thanks for point it out

                  Comment

                  Working...
                  X