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

Report
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.
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
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
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 6 343 344 //TEXT LOOP 345 //The following is a TEXT LOOP that will perform the same function 346 //for many variables. 347 //help foreach 348 foreach zazz09 in E F G { 349 replace `zazz09' = "1" if `zazz09' == "y" 350 destring `zazz09' , replace force 351 replace `zazz09' = 0 if `zazz09' == . 352 } 353 354 355 356 //Sum up the total attendance for each student. 357 //Notice the range has the form (firstvariable - secondvariable). 358 //help egen 359 //help rowtotal 360 egen days_present = rowtotal(Class-G) 361 362 //What is the maximum possible number of days of class? 363 //help max 364 365 //Option 1: Does your data have more than one group/class? If no, then use: 366 egen days_max = max (days_present) 367 368 //Option 2: Does your data have more than one group/class? If yes, then use: 369 //sort class 370 //by class: egen days_max = max(days_present) 371 372 373 //Calculate the attendance % for each student. 374 gen attendance_grade = days_present / days_max 375 //Extra: Can you calculate this using Excel? 376 order class Username attendance_grade 377 378 //Keep only the student name and attendance_grade variables. 379 keep class Username attendance_grade 380 381 //Let's calculate the average attendance grade for ACC 101. 382 383 //Option #1 384 egen mean_attendance1 = mean (attendance_grade) 385 386 //Option #2 387 sort class 388 by class : egen mean_attendance2 = mean (attendance_grade) 389 390 //Which option gives the correct average attendance for ACC 101? 391 drop mean_attendance1 392 drop mean_attendance2 393 394 //Save this file. Sort by Username (for merging by Username), then save. 395 sort Username 396 save topic1_attendance, replace 397 codebook Username 398 399 //Close the log file. 400 log close 401 translate lastname_firstname_YYYY-MM-DD- version .smcl lastname_firstname_YYYY-MM-DD- version . log 402 403 404 //********************************************************************* 405 //Homework #2: See the Blackboard Homework Folder for the homework assignment. 406 //********************************************************************* 407 408 409 410 411
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
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 7 412 //********************************************************************* 413 //Part 6: Merge the Grade Sheet and Attendance Sheet Together by Username. 414 //********************************************************************* 415 //Part 6A: Merge BY variable is Username. 416 //********************************************************************* 417 418 //Turn on the log function to record your keystrokes. 419 //Each time you run a log file, you have to select a NEW name. 420 log using lastname_firstname_YYYY-MM-DD- version 421 422 //Extra: In Excel, pull the attendance grades into the Fall 2013 ACC 101 sheet 423 //with the VLOOKUP command (linked by Username). 424 425 //In Stata, we will merge these two files together using the Username variable. 426 //Load the grade file, then sort by Username. 427 428 //help use 429 //How many students are listed? 6. 430 use topic1_101quizexam, clear 431 sort Username 432 433 //help codebook 434 codebook Username 435 436 //Merge using the 1:1 technique. 437 //We are merging BY Username, which means Username must be spelled exactly 438 //the same in both files to connect to each other. 439 //help merge 440 441 //Option #1 442 //Do you know if there is only one student in each file? If yes, use: 443 merge 1:1 Username using topic1_attendance 444 445 //Option #2 446 //Do you know if there is only one student in each file? If not, use the 447 //merge command without the 1:1 : 448 use topic1_101quizexam, clear 449 sort Username 450 451 merge Username using topic1_attendance 452 453 //If there are duplicates, use merge Username using topic1_attendance 454 //Look at the _merge variable. 455 //How many observations do we have in the merged file? 456 //Look at the screen. 19 + 4 = 23. 457 order _merge 458 save topic1_merged, replace 459 460 461 //********************************************************************* 462 //Part 6B: Merge values of 1, 2, and 3. 463 //********************************************************************* 464 465 //Reload the merged dataset. 466 //In the merged dataset, how many observations are there? 467 //From which file did each of the 23 observations come from? File 1? File 2? 468 use topic1_merged, clear 469 codebook Username 470 // 23 observations 471 472 codebook _merge 473 474 //Option #1: What if you want the merged file to keep students that were from 475 //the QUIZ/EXAM GRADESHEET (regardless of whether the student's name was 476 //from the ATTENDANCE sheet)? 477 //How many observations will there be? 478 keep if _merge == 1 | _merge == 3 479 codebook Username 480 481
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 8 482 //Option #2: What if you want the merged file to keep students that were from 483 //the QUIZ/EXAM GRADESHEET and also from the ATTENDANCE sheet? 484 //How many observations will there be? 485 use topic1_merged, clear 486 keep if _merge == 3 487 codebook Username 488 489 490 //Option #3: What if you want the merged file to keep students that were from 491 //the ATTENDANCE sheet (regardless of whether the student was listed on 492 //the QUIZ/EXAM GRADESHEET? 493 //How many observations will there be? 494 use topic1_merged, clear 495 keep if _merge == 2 | _merge == 3 496 codebook Username 497 498 499 500 //********************************************************************* 501 //Part 6C: Keeping merged values for students in QUIZ/Exam Sheet. 502 //********************************************************************* 503 504 //In the merged file, keep if the student was from the first dataset, 505 //(regardless of whether the student was listed on the second dataset 506 //attendance sheet). 507 use topic1_merged, clear 508 keep if _merge == 1 | _merge == 3 509 510 //How many students are there? 6 511 codebook Username 512 513 //Calculate the final overall %. 514 gen score = ( (.25*attend)+(.25*QuizAverage)+(.25*Exam1)+(.25*Final) )*100 515 order Username score 516 //Why are some scores missing with a . ? 517 518 //Drop the score calculation. 519 drop score 520 521 //Let's fill in the attendance score with 0 if it is missing. 522 order attend 523 replace attend = 0 if attend == . 524 525 //What is the class name? Why are there some rows with missing class names? 526 order class 527 //Why is the class name missing in 2 rows? 528 //Put the class name in the file. 529 replace class = "ACC 101" if class == "" 530 531 //Sort by Username for future merging. 532 sort Username 533 534 //Save this file. 535 save topic1_101grades, replace 536 537 //Outsheet the file to Excel. 538 outsheet using C:/ACCP476/topic1_101grades.xls, replace 539 540 541 //********************************************************************* 542 //Part 6D: Make 3 Tables for an analysis. 543 //********************************************************************* 544 //********************************************************************* 545 //NOTE: There are entire COURSES about Correlation and Regressions, 546 //so we can barely scratch the surface in this course ACCP 476. 547 //For an overview, please read the .pdf in our google drive, Topic 1 folder: 548 //"ACCP 476-CorrelationRegressionHandout" 549 550 //For this course, we will put aside the theory and proofs. 551 //We will focus on which commands to use to run the correlations and
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 9 552 //regressions. 553 //Interpreting these correctly will take some studying and time. 554 //********************************************************************* 555 556 //Table 1: Descriptive Statistics Table 557 //Calculate the N, Mean, 25%, Median, 75%, and standard deviation of your variables. 558 foreach variable in Final Exam1 QuizAverage attend { 559 tabstat `variable' , s( n mean p25 median p75 sd) 560 } 561 562 563 //Table 2: Correlation Table 564 //Make a correlation table to show the relationship between the variables. 565 pwcorr FinalExam Exam1 QuizAverage attend, star(.01) 566 pwcorr FinalExam Exam1 QuizAverage attend, star(.05) 567 pwcorr FinalExam Exam1 QuizAverage attend, star(.10) 568 569 570 //Table 3: Regression Analysis Table 571 // WARNING: You need to download the "outreg" command (for free) from Stata. 572 //Go to the HELP, SEARCH, SEARCH ALL, then type "outreg". 573 //Scroll to the bottom until you see "outreg" in blue. 574 //Click on the "outreg" link, then download the file. 575 576 //Simple OLS (Ordinary Least Squares) Regression. 577 xi : regress FinalExam 578 outreg2 using c:\ACCP476\topic1_regression.txt, stats(coef tstat) bdec(3) tdec(2) bracket replace 579 580 xi : regress FinalExam Exam1 581 outreg2 using c:\ACCP476\topic1_regression.txt, stats(coef tstat) bdec(3) tdec(2) bracket append 582 583 xi : regress FinalExam QuizAverage 584 outreg2 using c:\ACCP476\topic1_regression.txt, stats(coef tstat) bdec(3) tdec(2) bracket append 585 586 xi : regress FinalExam attendance 587 outreg2 using c:\ACCP476\topic1_regression.txt, stats(coef tstat) bdec(3) tdec(2) bracket append 588 589 xi : regress FinalExam QuizAverage Exam1 attendance 590 outreg2 using c:\ACCP476\topic1_regression.txt, stats(coef tstat) bdec(3) tdec(2) bracket append 591 592 //Make sure to Open Excel, then look for all .txt files to open, then oen up the regression results. 593 594 595 //Close the log file. 596 log close 597 translate lastname_firstname_YYYY-MM-DD- version .smcl lastname_firstname_YYYY-MM-DD- version . log 598 599 600 //********************************************************************* 601 //Homework #3: See the Blackboard Homework Folder for the homework assignment. 602 //********************************************************************* 603 604 605 606 607 608 //********************************************************************* 609 //Part 7: Create Appended data for class. 610 //NOTE: Make sure to have the HOMEWORK files handy during class. 611 //********************************************************************* 612 //Part 7A: Import and format the classes 101 and 102. 613 //Then append together. 614 //*********************************************************************
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
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 10 615 //Turn on the log function to record your keystrokes. 616 //Each time you run a log file, you have to select a NEW name. 617 log using lastname_firstname_YYYY-MM-DD- version 618 619 //help append 620 use topic1_101quizexam, clear 621 append using topic1_HW_102quiz, force 622 //Remember that HW1 contains ACC 102. 623 624 //Will this work as appended data? 625 order Username Exam* Final* 626 627 //Which class is 101? 102?? 628 //Clear the data. 629 clear 630 631 //Assign class name BEFORE the data is appended (If you can identify it). 632 //Load one file first. 633 use topic1_101quizexam, clear 634 //Since you know this is ACC 101, then just put the class name in. 635 gen class = "ACC 101" 636 order class 637 //Then append the data from homework (ACC 102). 638 append using topic1_HW_102quiz, force 639 //Now you can see which observations are for a different class. 640 replace class = "ACC 102" if class == "" 641 642 643 //Where are the Exam1 and FinalExam grades for ACC 101 and ACC 102? 644 order Exam* Final* 645 646 //To line up the same data, we must replace the data (If you can identify it). 647 replace Exam1 = Exam_1 if Exam1 == . 648 drop Exam_1 649 replace FinalExam = Final_Exam if FinalExam == . 650 drop Final_Exam 651 652 //Reorder. 653 order class Username QuizAverage Exam1 FinalExam 654 655 //Simplify the file. 656 keep class Username QuizAverage Exam1 FinalExam 657 658 659 //Prepare to merge with the attendance sheet by USERNAME. 660 //Will a 1:1 merge work? 661 //To identify duplicates. 662 sort Username 663 gen dup = 1 if Username == Username[_n-1] 664 order dup 665 codebook dup 666 667 //Are there any duplicates? 668 drop dup 669 670 //Do a double-sort on how we plan to merge: by CLASS, then USERNAME. 671 sort class Username 672 673 //Save the file. 674 save topic1_101_102_appendedquiz, replace 675 676 677 //********************************************************************* 678 //PART 7B: Merge file topic1_101_102 with the MESSY attendance file: 679 //(topic1_HW2). Pay attention to how topic1_HW2 was sorted and what the 680 //merging variable is. 681 //********************************************************************* 682 683 //Look at the file topic1_HW2. We need to re-sort and re-save to prepare for 684 //merging
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 11 685 use topic1_HW_attendance, clear 686 687 //Go ahead and sort by class and Username 688 order class Username 689 sort class Username 690 691 //So do we have repeats in the file? (73 total and 69 unique) 692 codebook Username 693 694 sort class Username 695 //Save as another name with "_v2"; do not overwrite. 696 //Why didn't I pick the name topic1_HW_attendance ? 697 save topic1_HW_attendance_v2, replace 698 699 700 //Load the first file: topic1_101_102. 701 use topic1_101_102_appendedquiz, clear 702 703 //Sort by class and Username. 704 sort class Username 705 merge 1:1 class Username using topic1_HW_attendance_v2 706 707 order _merge 708 709 //Keep if student was listed in the Quiz/Exam file. 710 keep if _merge == 1 | _merge == 3 711 sort class Username 712 713 save topic1_101_102_grades_v2, replace 714 715 //In the merged dataset, how many students were from File1 but not from File2? 716 //In the merged dataset, how many students were from File2 but not from File1? 717 //In the merged dataset, how many students were from both File1 and File2? 718 //In the merged dataset, how to keep students that were from File 1? 719 //In the merged dataset, how to keep students that were from File 2? 720 721 722 //Close the log file. 723 log close 724 translate lastname_firstname_YYYY-MM-DD- version .smcl lastname_firstname_YYYY-MM-DD- version . log 725 726 //********************************************************************* 727 //Homework #4: See the Blackboard Homework Folder for the homework assignment. 728 //********************************************************************* 729 730 731 732 //Helpful Stata Hints 733 734 //Use counters to number the rows for analysis: _n 735 736 //Missing numerical values are . 737 //Missing text values are "" 738 739 //Rename columns to help with the analysis. 740 //Reorder columns to help with long pieces of data, like attendance and quizzes. 741 742 //To keep only one row of the data, sort by the variable (usually username), 743 //then keep if it is not qual to the one above: 744 //sort Username 745 //keep if Username ~= Username[_n-1] 746 747 748 749 750 //********************************************************************* 751 //EXCEL COMMANDS: 752 //********************************************************************* 753
ACCP476_Topic1_Commands_2022-08-16A - Printed on 8/16/2022 3:25:24 PM Page 12 754 //(1) IF THEN 755 756 //(2) AVERAGE 757 //How does Excel treat missing numbers? 758 //How does this compare to how Stata treats missing numbers? 759 760 //(3) VLOOKUP 761 762 //(4) SMALL (for the Nth smallest value) 763 764 //(5) LARGE (for the Nth largest value) 765 766 767 768 //********************************************************************* 769 //Homework #5: See the Blackboard Homework Folder for the homework assignment. 770 //********************************************************************* 771
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