Announcement

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

  • Help with Regression Commands

    I am supposed to display a graph comparing the results by gender and students of multiple variables. It was a randomized study where certain students and faculty were sent a specific email.

    The gender column in my .dta file is categorical. Male is listed as M. Female is listed as F.

    My do file is not giving me any results.

    Here is an explanation of the project. I have attached my code along with the results I receive in Stata:

    The project consisted of a random set of students and faculty being sent a specific email. The analysis looked at how opened the email, clicked the link, total clicks, and who completed the survey.

    I am responsible for creating graphs based that shows the results by gender for students and faculty. For the opened_first, clicked_first, and completed survey variable.

    Any help would be greatly appreciated!



    tabulate gender, generate(gender)
    set more off
    foreach var opened_first clicked_first clicked Totalclick survey {
    forvalues i=0(1)1 {
    di "FEMALE" `var'"
    reg `var' social_treatment if gender1==1 & social_treatment_student==`i'
    estimates store gender1`i'
    di "MALE" `var'"
    reg `var' social_treatment if gender2==1 & social_treatment_student==`i'
    estimates store gender2`i'
    }

    -end-
    Attached Files
    Last edited by April Trichelle; 08 Jun 2019, 16:46.

  • #2
    In general, to troubleshoot problems with code, it is important to show not just the code, but also the output, including any error messages, it is generating. It is also usually best to include example data that produces the problem you are concerned with, and a more precise description of the problem than "it is not working." I hope that in the future you will do those things and, more generally, follow the excellent advice in the Forum FAQ on how to get the most out of your Statalist experience.

    That said, there is one error in the code that stands out to me. Your foreach command should be:

    Code:
    foreach var of varlist opened_first clicked_first clicked Totalclick survey {
    Last edited by Clyde Schechter; 08 Jun 2019, 16:31.

    Comment


    • #3
      Thank you for the information. I have edited my post with the output and the error message I am receiving.

      Comment


      • #4
        Thanks.

        I see two other problems, in your -display- commands you have unbalanced " characters. They should read - display "FEMALE `var'"- and -display "MALE `var'"-, respectively.
        Last edited by Clyde Schechter; 08 Jun 2019, 16:51.

        Comment


        • #5
          I have made the adjustments and I am getting the same error. I am not sure what is going one. Here is some of my data.

          Comment


          • #6
            Please read the Forum FAQ, with special attention to #12 on the best ways to give data, code, etc. In particular, attachments are discouraged. Many of us, and I am one, will not download attachments coming from strangers. Especially Word documents, which can contain active malware.

            Comment


            • #7
              Thanks again. Here is my code from dataex command. I have deleted the attachment.
              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              
              clear
              
              input byte social_treatment str1 gender float(clicked_first opened_first survey student faculty)
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 1 0 0 1
              
              0 "F" 0 0 0 0 1
              
              1 "F" 0 1 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 1 0 0 1
              
              1 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 1 0 0 1
              
              1 "F" 0 1 0 0 1
              
              1 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 1 0 0 1
              
              0 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 0 0 0 1
              
              1 "F" 0 1 0 0 1
              
              1 "F" 0 0 0 0 1
              
              0 "F" 0 1 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 1 0 0 1
              
              0 "F" 0 0 0 0 1
              
              0 "F" 0 0 0 0 1
              
              1 "M" 1 1 0 0 1
              
              1 "M" 0 0 0 0 1
              
              1 "M" 1 1 0 0 1
              
              1 "M" 0 0 0 0 1
              
              1 "M" 0 0 0 0 1
              
              1 "M" 0 0 0 0 1
              
              1 "M" 0 0 0 0 1
              
              1 "M" 0 1 0 0 1
              
              0 "M" 0 1 0 0 1
              
              end

              Comment


              • #8
                That said, I created a toy data set with variables like the ones you describe. Even after fixing the -foreach- and the -display- statements, the code still creates the error you are describing. And the reason is that there is no curly closing brace character "}" to balance the outermost foreach.

                The following code is fixed up and runs without errors on my computer:

                Code:
                //    CREATE DEMONSTRATION DATA SET
                clear*
                set obs 100
                gen gender = cond(mod(_n, 2), "M", "F")
                gen social_treatment_student = (_n <= 50)
                set seed 1234
                foreach x in opened_first clicked_first clicked Totalclick survey {
                    gen `x' = rnormal()
                }
                
                //    HERE IS FIXED CODE
                tabulate gender, generate(gender)
                set more off
                foreach var of varlist opened_first clicked_first clicked Totalclick survey {
                    forvalues i=0(1)1 {
                   di "FEMALE `var'"
                    reg `var' social_treatment if gender1==1 & social_treatment_student==`i'
                    estimates store gender1`i'
                   di "MALE `var'"
                    reg `var' social_treatment if gender2==1 & social_treatment_student==`i'
                    estimates store gender2`i'
                    }
                }
                Note, by the way, that when you indent code, the absence of a closing } becomes visibly obvious, whereas when the code is just written as an unformatted block, it isn't apparent unless you sit there and count opening and closing braces (which is, needlessly to say, both tedious and error-prone). Do develop the habit of indenting your code. Over the years it will save you enormous amounts of time, not to mention frustration.

                Added: Thank you for #7, with which the above crossed.

                Comment


                • #9
                  Thank you it worked!

                  Comment

                  Working...
                  X