ACCP476_Topic1_Commands_2022-08-16A

.pdf

School

CUNY Hunter College *

*We aren’t endorsed by this school

Course

27100

Subject

Accounting

Date

May 8, 2024

Type

pdf

Pages

12

Uploaded by BarristerRainDeer10 on coursehero.com

ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 1 1 //Dr. Michelle Liu 2 //ACCP 476 3 //Topic 1 4 5 6 //For Stata resources (cheat sheets, videos, links): 7 // https://www.stata.com/bookstore/stata-cheat-sheets/ 8 // https://www.stata.com/teaching-with-stata/ 9 // https://www.stata.com/links/ 10 11 //Note: The double-slashes // serve to INACTIVATE commands. 12 //You ACTIVATE commands by removing the double-slashes. 13 14 15 16 //********************************************************************* 17 //Part 1: Setup directory, then turn on the log function to "record" your keystrokes. 18 //********************************************************************* 19 20 //Note: To set Stata up for the first time: 21 cap log close 22 set more off, permanently 23 24 //EVERY .do file must have the following commands to setup the directory. 25 26 //For PCs, set your own directory: 27 cd C:/ACCP476/ 28 //Note: For Stata help, just type the word "help", and then "command": 29 //help cd 30 31 //For Macs, use pwd, then set your own directory: 32 //help pwd 33 pwd 34 cd /Users/XXX/Documents/Stata/ACCP476/ 35 36 //Turn on the log function to record your keystrokes. 37 //Each time you run a log file, you have to select a NEW name. 38 log using lastname_firstname_YYYY-MM-DD- version 39 40 41 42 //********************************************************************* 43 //STATA TOPIC 1: Import, format, calculate, then export grades. 44 //********************************************************************* 45 //GENERAL RULE: All data needs to be in NUMERICAL format for analysis. 46 // Calculate student grades based on the following: 47 // Average Quiz Grade, Drop Lowest (25%) 48 // Exam 1 (25%) 49 // Final Exam (25%) 50 // Attendance Sheet (25%) 51 52 53 54 //********************************************************************* 55 //Part 2: Import the Grade Sheet for Fall 2013 ACC 101. 56 //********************************************************************* 57 58 //Setup the source folder. 59 //Download the excel sheet starting with "topic1_2013-01-FallGrades_2021-08-19.xlsx" into the 60 //source folder (which will not be touched). 61 62 //EXCEL: Download another copy of the excel sheet into the ACCP476 folder. 63 //Save this file with your initials at the end. 64 //Open the file. Calculate the grade using excel. 65 66 67 //For PCs: Import the Grade Sheet for Fall 2013 ACC 101. 68 import excel using "C:/ACCP476/source/topic1_2013-01-FallGrades_2021-08-19.xlsx" , clear firstrow sheet(ACC101) 69
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 2 70 //For MAC: Import the Grade Sheet for Fall 2013 ACC 101. 71 import excel using "/Users/XXX/Documents/Stata/ACCP476/source/topic1_2013-01-FallGrades_2021-08-19.xlsx" , clear firstrow sheet(ACC101) 72 73 //For MACs 74 //http://macstata.blogspot.com/2007/11/step-1-installation-and-working.html 75 //https://www.techtips.surveydesign.com.au/post/change-your-stata-interface-for-both-windows- and-mac 76 77 78 79 //********************************************************************* 80 //Part 3: Look at the data. 81 //********************************************************************* 82 83 //What do variables in red signify? 84 //What do variables in black signify? 85 86 //Calculate the average quiz grade. 87 //You can create a variable with any name with the generate (gen) command. 88 //help gen 89 90 gen zazz01 = (Quiz1 + Quiz2 + Quiz3 + Quiz4)/4 91 //help order 92 order Username Quiz* zazz01 93 94 //What does the . mean? 95 //Do we fill in the missing values? 96 97 98 //Does this give the average quiz grade? 99 //help drop 100 drop zazz01 101 102 //For quizzes, fill in the missing . with zero (the correct grade). 103 //Option #1: 104 //help replace 105 replace Quiz1 = 0 if Quiz1 == . 106 replace Quiz2 = 0 if Quiz2 == . 107 108 //NUMERIC LOOP 109 //Option #2: Use a NUMERIC LOOP to replace . with zero for Quizzes 3 and 4. 110 //help forval 111 forval zazz02 = 3/4 { 112 replace Quiz `zazz02' = 0 if Quiz `zazz02' == . 113 } 114 115 //Calculate the average quiz grade. 116 gen zazz03 = (Quiz1 + Quiz2 + Quiz3 + Quiz4)/4 117 118 // help order 119 order Username Quiz* zazz03 120 //Does this give the average quiz grade? 121 122 //What does the * mean in Quiz* ? 123 //* is a wildcard. You can place it before or after a term. 124 125 //However, we want to drop the lowest quiz grade in the quiz average. 126 //So let's get rid of the Quiz Average we just calculated. 127 // help drop 128 drop zazz03 129 130 //Identify the lowest quiz grade. 131 //EGEN is for statistical commands. 132 //GEN is for general commands. 133 //help egen 134 //help rowmin 135 egen zazz04 = rowmin (Quiz1 Quiz2 Quiz3 Quiz4) 136 //This is the lowest quiz grade.
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 3 137 order Username Quiz* zazz04 138 139 //Now remove the lowest quiz grade when calculating the average. 140 gen zazz05 = (Quiz1 +Quiz2 +Quiz3 +Quiz4 - zazz04)/3 141 order Username Quiz* zazz04 zazz05 142 143 //Keep the username and the variables needed to calculate the grade. 144 //To make things easier, rename the variable as "QuizAverage". 145 //Which variable was the quiz average? 146 rename zazz05 QuizAverage 147 order Username QuizAverage 148 149 //Extra: In Excel, calculate the highest 3 quiz grades by doing the following: 150 //Option #1: Use the LARGE command to get the 1st, 2nd, and 3rd highest 151 //quiz grades. 152 //Option #2: Get the Total of all quiz grades, then subtract out// 153 //the lowest grade with the SMALL command. 154 155 //What about the missing . values for Exam 1 and Final Exam? 156 //Maybe some students have dropped the class. 157 //Fill in the missing . with zero. 158 replace Exam1 = 0 if Exam1 == . 159 replace FinalExam = 0 if FinalExam == . 160 161 order Username QuizAverage Exam1 FinalExam 162 163 //help keep 164 keep Username QuizAverage Exam1 FinalExam 165 166 //What is the median of QuizAverage? 167 egen zazz50 = median(QuizAverage) 168 egen zazz51 = pctile(QuizAverage), p(50) 169 170 //What is the 25th and 75% percentile of Exam1? 171 egen zazz52 = pctile(Exam1), p(25) 172 egen zazz53 = pctile(Exam1), p(75) 173 174 175 //Sort by Username (for merging by Username), then save. 176 //help sort 177 //help gsort 178 179 //What if we want to sort by Username? 180 sort Username 181 gsort +Username 182 183 //What if we want to REVERSE sort by Username? 184 gsort -Username 185 186 //Restore the sort by Username. 187 gsort +Username 188 189 //Save the file. 190 //help save 191 save topic1_101quizexam, replace 192 193 194 195 //********************************************************************* 196 //Part 4: Close the log, then translate it. Then upload the log to Blackboard. 197 //********************************************************************* 198 199 log close 200 201 //The translation command must have the same file name as in the log using command. 202 translate lastname_firstname_YYYY-MM-DD- version .smcl lastname_firstname_YYYY-MM-DD- version . log 203 //Look in your folder for the .txt file with the above name. 204 //When completing homework, you will copy then paste the contents of the 205 //.txt file to Blackboard.
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 4 206 207 208 //********************************************************************* 209 //Homework #1: See the Blackboard Homework Folder for the homework assignment. 210 //********************************************************************* 211 212 213 214 215 216 217 218 //********************************************************************* 219 //Part 5: Incorporate attendance as part of the grade. 220 //********************************************************************* 221 //Part 5A: APPENDED DATA: Import the Attendance Sheet from the Excel file. 222 //********************************************************************* 223 224 //Turn on the log function to record your keystrokes. 225 //Each time you run a log file, you have to select a NEW name. 226 log using lastname_firstname_YYYY-MM-DD- version 227 228 //PC Users 229 import excel using "C:/ACCP476/source/topic1_2013-01-FallGrades_2021-08-19.xlsx" , clear firstrow sheet(Attendance) 230 231 //Mac Users 232 import excel using "/Users/XXX/Documents/Stata/ACCP476/source/topic1_2013-01-FallGrades_2021-08-19.xlsx" , clear firstrow sheet(Attendance) 233 234 //What type of data is this? 235 //Does this sheet contain data for more than one class? 236 //This is APPENDED data. 237 238 //How do we keep only the rows for ACC 101? 239 //Let's calculate the attendance grade for all three classes. 240 241 //Which rows contain the data for students from ACC 101? ACC 102? ACC 110? 242 //What does the _n do? 243 //Assign a counter variable to number the rows. 244 gen zazz06 = _n 245 order zazz06 246 247 248 //Assign class names to each of the rows. 249 //Generate a blank text variable, then fill it in. 250 gen zazz07 = "" 251 order zazz06 zazz07 252 253 //Only replace variables if the current value is EMPTY. 254 replace zazz07 = "ACC 110" if zazz07 == "" & zazz06 <= 12 255 replace zazz07 = "ACC 101" if zazz07 == "" & zazz06 >= 13 & zazz06 <= 22 256 replace zazz07 = "ACC 102" if zazz07 == "" & zazz06 >= 23 257 258 //Rename the variable zazz06 as counter. 259 //help rename 260 rename zazz06 counter 261 262 //Rename the variable zazz07 as class. 263 //help rename 264 rename zazz07 class 265 266 267 //How will we match the correct student from attendance to the exam grades? 268 //Identify the username, then re-name the variable "Username" to match. 269 //We will later merge by "Username". 270 rename C Username 271 order counter class Username 272
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 5 273 274 //How many students are in ACC 101? 275 //Use the count function. 276 //help count 277 278 //Option #1 279 egen zazz08 = count(Username) 280 //help order 281 order counter class Username class Username zazz08 282 rename zazz08 nstudents1 283 //Is this the correct number of students for ACC 101? 284 285 286 //Option #2 287 //Now try to count the Usernames BY class. 288 //SORT, then use BY command. 289 //Single sort. 290 sort class 291 //Double sort. 292 gsort + class -Username 293 by class : egen nstudents2 = count(Username) 294 order counter class Username nstudents* 295 //What does the * mean? 296 //Why is the counter variable scrambled? 297 298 299 //********************************************************************* 300 //Part 5B: Calculate the % of days attended. 301 //********************************************************************* 302 303 //Re-sort the data by class 304 sort class 305 306 //Re-sort the data by class and counter 307 sort class counter 308 order class counter 309 //How does the double-sort look different? 310 311 312 //How do we calculate attendance? 313 //Simplify the data. Keep columns needed for attendance. 314 keep class Username nstudents* Class-G 315 316 //Simplify the data. Keep the rows needed for attendance. 317 //Keep if the Username is not missing. 318 //Is Username a text or a numerical variable? 319 keep if Username ~= "" 320 321 322 //How many days did people attend class? 323 324 //What does the "y" mean? Consider "y" to mean "present" for that day. 325 //Convert the attendance text "y" into a number. 326 //Assign 1 for attended and 0 for absent, then calculate the average. 327 //Start with one variable. 328 //Replace the text y with the text number 1. 329 //help replace 330 replace Class = "1" if Class == "y" 331 332 //Now convert text 1 (in red) to the number 1 (in black). 333 //help destring 334 destring Class, replace force 335 //Why are there . ? 336 //What happened to the other text? 337 338 //Replace missing . with 0. 339 replace Class = 0 if Class == . 340 341 //What is the condition for identifying MISSING TEXT vs. MISSING NUMBER? 342
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help