Using Stata for Survey Data Analysis
Download 1.39 Mb. Pdf ko'rish
|
2009 Usingstataforsurveydataanalysis (1)
- Bu sahifa navigatsiya:
- Using functions
- Table 7. Examples of functions available in Stata Function Meaning Example
Minot
Using Stata for Survey Analysis Page 26 replace Paro = 1 if dzongkha==3 Or you can get exactly the same result with just one command: generate Paro = (dzongkha==3) If the expression in parentheses is true, the value is set to 1. If it is false, the value is 0. The “or” and “and” operators are useful if you want to impose more than one condition. For example, suppose you want to create a dummy variable for female household heads in Paro. In other words, a household must be both in the dzongkhag of Paro and be female headed to be selected. gen Paro_fem = 0 replace Paro_fem = 1 if dzongkha==3 & b21_q1==2 or an easier way to do this would be: gen Paro_fem = (dzongkha==3 & b21_q1 ==2) Or suppose you wanted to create a dummy variable for households in the west and central regions. This means a household can be in the west or it can be in the central Region to be selected. This variable can be created with: gen west_cent = 0 replace west_cent = 1 if region==1 | region==2 or by one command: gen west_cent = (region==1 | region==2) You can also combine conditions using parentheses. Suppose you wanted a dummy variable that indicates if a household in one of these regions is headed by a woman. The command would be: gen west_cent_FP = ((region==1 | region==2) & b21_q1==2) Using functions Stata has about 180 functions for statistics, trignometry, probability distributions, programming, and manipulating strings (text). Below is a small sample, including some of the more useful functions. Other functions can be found by typing “help functions” in the Command window. Table 7. Examples of functions available in Stata Function Meaning Example abs(x) computes the absolute value of x abs(-2) = 2 exp(x) calculates e to the x power. exp(1) = 2.7182818 ln(x) computes the natural logarithm of x ln(10) = 2.3025851 log(x) is a synonym for ln(x), the natural logarithm. log(10) = 2.3025851 log10(x) computes the log base 10 of x. log10(1000) = 3 sqrt(x) computes the square root of x. sqrt(36) = 6 int(x) gives the integer obtained by truncating x. int(3.8532) = 3 round(x,y) gives x rounded into units of y. round(3.8532) = 4 norm(z) provides the cumulative standard normal. norm(0) = 0.5 chi2(n,x) returns the cumulative chi-squared distribution with n degrees of freedom chi2(100,80) = .07033507 reverse(str) reverse the order of letters in a string (text data) reverse(mood) = doom uniform() generates a random number between 0 and 1 random() = 0.739538 Download 1.39 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling