Stata
Stata
Stata
use "roster"
*opens the roster dataset. You can also directly click the dta file or
tab age
*Disables the annoying "more" option displayed everytime you run a command that obtains results so long, they can't fit in the screen all at
once.
*String variables can hold non-numeric characters as well. No mathematical operation can be formed on them
tab age
summarize age
drop if age==2018
tab sb1q4
*Or
drop if sb1q4==0
*restricting the observations for which the age variable is being summarized,
*to only female respondents (compare female age stats with overall stats)
count if sb1q4==1 & age<18
*TASK: How many respondents are above or equal to 18 and either separated or
*divorced?
*Two-way tabulation. Breakdown of respondents in each marital status category by gender, or, breakdown of male and female respondents by
the marital status category (depends if you are following values
*horizontally or vertically). Try the "column", "row", "column nofreq" and "row nofreq" options with the tab command (feel free to use the help
file to see how to use these options)
*and see how you can enhance the results obtained from this two-way tabulation command.
use "roster"
drop if age==2018
preserve
drop sb1q62
restore
codebook age
codebook district
list age in 1/5
ed
*saving dataset
1) Renaming Variables
6) Merging Datasets
7) Reshaping Datasets
*/
tab gender
tab gender
*TASK: In the marital status variable, replace the 0 values with missing values
use "roster"
gen female=0
/*We can now assign value labels to the female variable through the following
two-step procedure:
tab female
tab female
*TASK: Now generate a variable named "Male". It should take the value 1 for
*male respondents and 0 for female respondents. Assign value labels to this
*variable.
*To verify that you have generated the correct binary variable for male:
tab sb1q11
tab sb1q11
tab sb1q11
tab sb1q11
describe sb1q7
gen divorced=0
tab divorced
*TASK: Generate a binary variable and name it "married". It should take the
*TASK: Convert the district variable from numeric to string. Transform the
di subinstr("Ec00nometrics","00","o",.)
di subinstr("IceCCCCCCCCCCream","C","",.)
di subinstr("Iceream","er","ecr",.)
***Replace @ with a
di substr("Econometrics",1,3)
di substr("Econometrics",6,.)
di substr("Econometrics",-3,.)