research paper 180

profileJaneeee
Week9_in_class_stata.do.txt

*********************** ** to make sure the analysis process run smoothly ** we need to first learn how STATA works and prepare several things before analysis *********************** **** several files are needed when we analyze data in STATA**** /* 1). log file: A Stata log file is an electronic record of your commands and results that can be printed or saved to a file. 2). do file: The do-file contains the Stata commands that you wish to execute. Executing a do-file is the same as executing a series of commands interactively, only you have a permanent record of your commands. This allows you to quickly reproduce work you have already done and go from there. You will never have to make the same mistake twice! Just as important, others can see exactly what you did and build off of your work. * you can also use do file to keep any notes you want by using *, //. /**/. 3) dta file: dta file simply means the data file you wish to analyze. We can easily convert a excel file in to dta file.*/ *** Normal steps for analysis *** /* 1) start a log file to keep track of everything you will do later on. 2) write notes that contains some information about this analysis. (date of analysis, your name, etc) 3) load data file (dta file) 4) analysis (different commands for your statistical analyses) 5) save your dta file (it is always good to save your dta file after anlayses regardless if you made any changes to the dataset) 6) save your log file */ /* Lets start */ /*step 1: log file*/ * change the following line so the correct folder is named log using "E:\180AW_Spring_2019\class_practice.log", replace // "replace" command ********************************** * Spring 2019 SOC 180AW * Langou Lian * Date started: 05/20/2019 * Last revision date: 05/29/2019 by WeiWei * Today's date: 05/29/2019 ********************************** set more off // this command tells STATA to show part of the results rather than full results. /*step 3: load data file*/ * Open a data file and look at what variables we have in the datasetare available * change the following line so the correct folder is named * If the data is in a excel format, we need to change it and load it as a dta file. *import excel "E:\180AW_Spring_2019\OscarMovieDataset.xlsx", sheet("Cleaned") cellrange(A1:Q1551) firstrow clear /* if you save your data as dta file after your first time of analysis, you can load it again next time by simply typing the following command */ use "E:\180AW_Spring_2019\OscarMovieDataset.dta", clear /*step 4: data analysis*/ * describe the variables describe * browse the dataset browse * to add numerical labels to the values in the output numlabel, add browse // what has changed? * clean data drop if nomn==99 //drop miscoded variable values * Part 2 * Descriptive and inferential statistics * get descriptive statistic for budget, including all movies summarize budget // sum command gives you descriptive statistics for continuous variables. * get a frequency and percentage distribution for nomination tab nomination // tab command can be used to analyze categorical variables. /* get descriptive statistics for budget, including only movies that are nominated */ sum budget if nomination==1 * Questions * How many movies are nominated? /* How does the mean $ of budget differ between the whole sample and the subsample of movies that are nominated?*/ * find the mean and 95% CI for budget, including only movies that are nominated mean budget if nomination==1 * find the mean and 99% CI for budget, including only movies that are nominated mean budget if nomination==1, level(99) * Question * How does the 95% CI differ from the 99% CI? * How would you describe each CI in words? * do a t-test of whether the mean budget of nominated movies is equal to the mean budget of unnominated movies sdtest bdgt,by(nomn) //variance ratio test ==> unequal variances ttest bdgt, by(nomn) unequal //"unequal" is for different variances *t-test comparing the budget means of nominated vs unominated movies sdtest rt,by(year) tab year //detect an incorrectly coded cases year==2015 replace year=. if year==2015 //replace year==2015 with missing data sdtest rt,by(year) //equal variances ttest rt, by(year) //no need to add "unequal" * Question * How do you interpret the probabilities one the last line of the t-test output? *Part 3 *Cross-tabulation (two-way tabulation) *Cross-tabluations summarize the relationship between two discrete variabels /*we use the command tab for tabulate-- tab (rvar) (cvar)*/ tab drm nomn replace drm=. if drm==99 tab drm nomn, co //show within-colum percentages--we have the column sum up to 100% tab drm nomn, ro // show within-row percentaes--we have the row sum up to 100% tab drm nomn, ro co nof //only shows the percentages—no frequencies *Add the statistics--testing the significance tab drm nomn, ro co expected chi2 lrchi2 exact gamma /*chi2 gives you the Pearson chi- square, expected gives you the expected frequencies lrchi2 gives you the Likelihood Ratio Chi-Square; exact gives you Fisher’s Exact Test; and gamma gives you the Goodman and Kruskal's gamma statistics*/ tab drm nomn, ro co chi2 *Question: how to interpret chi-squared test result? /*step 4: draw and save graphs*/ * Graphs * Histograms and box plots * get a histogram for budget for movies who are nominated histogram bdgt if nomn==1 graph export "graph1.pdf", replace * get histograms separately for movie released in 2017 and 2018, express the graphs in percents /* in this case, year is a continuous variable. We might need to first convert it to a categorical variable*/ histogram bdgt if nomn==1, percent by(year) graph export "graph2.pdf", replace * box plots graph box bdgt if nomn==1 graph export "graph3.pdf", replace * box plots graph box bdgt if nomn==1, over(year) graph export "graph4.pdf", replace * scatterplots scatter rt usrt replace rt=. if rt==99 replace usrt=. if usrt==99 scatter rt usrt graph export "graph5.pdf", replace /*step 5: save your log file*/ *************************************** log close clear