- Bootstrap sampling and estimation, Survey data analysis in Stata
- Starting from Stata 10, you can just use -svy jackknife- instead of creating jackknife weight at first.
- By using information on PSUs and strata, -svy jackknife:- will automatically adjust the sampling weights to produce the replicates using the delete-1 jackknife method
- if you want do delete-k jackknife, you need provide the replicate weight variables using -svyset-
- by default jackknife variance is computed by using deviations of the replicates from their mean. If you want to variance from the observed value of statistics based on the entire dataset, you need use -svy jackknife, mse- (mean square error)option. The -mse- method providea larger variance estimation because of the addition of the familiar sqared bias tern in the mean square error
- The Stata 14 has "strata()" and "cluster()" options and sounds like for the complex survey data, but seemingly it cannot deal with the sampling weight correctly.
- for example: bootstrap "stata_program" _b, strata(strata) cluster(psu) reps(1000) // no weight in the statement
- I tend to avoid to use this bootstrap command for complex survey data
- I will use -bsweights- creates the bootstrap resampling weights then used the weights by -svyset-, -svy bootstrap- or -bs4rw-. Resampling variance estimation for complex survey data - The Stata Journal. -bsweights- was written by Stas Kolenikov (Survey bootstrap and bootstrap weights).
- or, SURVWGT: a Stata module to create and manipulate survey weights by Nickolas Winter
- Jackknife for simple random sampling data:
- jknife r(mean): summarize mpg
- Jackknife for complex survey data:
- webuse nhanes2, replace
- svyset psu [pw=finalwgt], strata(strata)
- svy jackknife slope=_b[height] constant=_b[_cons]: regress weight height
- Jackknife for complex survey data using a user-written program:
- svy jackknfie _b[, options]: intcens
- User-written program using Jackknife for complex survey data.
- Notes:
- -svy jackknife- is allowed as long as they follow standard Stata -syntax-, allow the -if- qualifier, and allow -pweights- and -iweights-.
- Notes: "anything", "namelist", "name", "weight, "if", "in", "varlist", "using", "exp", etc. are special macros. "anything" is used to tell the -syntax- command what can appear immediately after the name of the command. "anything" could be anything like SILLY in this example, which passes an arguement into the program. Things between "[" and "]" are optional. In order to use -margins-, -set buildfvinfo- needs set as -on-.
- Here is a modified example in the manual: with replication-based variance estimators
- program
mymargins, eclass
syntax anything [if] [iw pw]if "`weight'" != "" {local wgtexp "[`weight' `exp']"}set buildfvinfo on`anything' `if' `wgtexp'margins race, postendglobal myanything "logistic highbp height weight i.race c.age##c.age" //!!! using `anything' with caution !!!svy jackknife _b: mymargins $myanything
- UCLA: How do I write my own bootstrap program?
- SSCC: Bootstrapping in Stata
- Stata Journal(2003): Bootstrapped standard errors
- Schmidheiny(2016): The Bootstrap
- How can I analyze multiple mediators in Stata?
- Stata Journal(2004): From the help desk: Some bootstrapping techniques
- 'svr' is a module/package to compute estimates with survey replication (SVR) based standard errors written by Nick Winter. -survwgt-, one of commands of 'svr' creates sets of replicate weights for complex sampling data including balanced repeated replication (BRR) and several version of the survey jackknife (JK*). In addition, survwgt performs oststratification, raking, and non-response adjustments to survey weights. Starting from Stata 10, you can just use -svy jackknife- instead of creating jackknife weight at first.
- The jackknife (n-1) estimate of the standard error is equal to
, where n is the total number of observations (or clusters). The factor in the jackknife's standard error is about n times (inflation factor) larger than bootstrap [1/(B-1)].
- The delete-d jackknife estimate of the standard error is using (n-d)/C(n,d) instead of (n-1)/n
- Efron (1981). Nonparametric Estimates of Standard Error: The Jackknife, the Bootstrap and OtherMethods
- McIntosh."The Jackknife Estimation Method"
- UCLA:How can I sample from a dataset with frequency weights?
Disclaimer: This blog site is intended solely for sharing of information. Comments are warmly welcome, but I make no warranties regarding the quality, content, completeness, suitability, adequacy, sequence, or accuracy of the information.
Friday, December 16, 2011
Doing bootstrap/jackknife in Stata
Journal Article - Heart Disease and Stroke Statistics—2012 Update from the AHA
Journal Article - Heart Disease and Stroke Statistics—2012 Update from the AHA
"Each year, the American Heart Association (AHA), in conjunction with the Centers for Disease Control and Prevention, the National Institutes of Health, and other government agencies, brings together the most up-to-date statistics on heart disease, stroke, other vascular diseases, and their risk factors and presents them in its Heart Disease and Stroke Statistical Update. The Statistical Update is a valuable resource for researchers, clinicians, healthcare policy makers, media professionals, the lay public, and many others who seek the best national data available on disease morbidity and mortality and the risks, quality of care, medical procedures and operations, and costs associated with the management of these diseases in a single document." …
Full text: here (pdf)
Wednesday, December 14, 2011
Is a Chow test the correct test to determine whether data can be pooled together?
Source: Stata FAQs by Willam Gould
A Chow test is simply a test of whether the coefficients estimated over one group of the data are equal to the coefficients estimated over another, and you would be better off to forget the word Chow and remember that definition.
History: In the days when statistical packages were not as sophisticated as they are now, testing whether coefficients were equal was not so easy. You had to write your own program, typically in FORTRAN. Chow showed a way you could perform a Wald test based on statistics that were commonly reported, and that would produce the same result as if you performed the Wald test.
Full text: here
Other related articles about Chow test:
- Stata: How can I compute the Chow test statistic? (Chow tests are the same as the Wald test "test" command reports)
- Stata: Can you explain Chow tests?
- Chow test - Wikipedia
- Stata: In Stata, how do I conduct the Chow Test?
- Gregory C. Chow (1960). "Tests of Equality Between Sets of Coefficients in Two Linear Regressions"
- My thoughts: I use 'suest' and 'Chow' test to test differences of coefficients. [Stata 12 help - Contents; the Stata Journal archives]
Role of Environmental Chemicals in Diabetes 1 and Obesity
By Kristina A. Thayer, Jerry Heindel, John R. Bucher, Michael A. Gallo
Tips - Stata: How do I fit a linear regression with interval (inequality) constraints in Stata?
Source: Stata FAQs by Isabel Canette
If you need to fit a linear model with linear constraints, you can use the Stata command cnsreg. If you need to fit a nonlinear model with interval constraints, you can use the -ml- command, as explained at http://www.stata.com/support/faqs/stat/intconst.html. However, if you have a linear regression, the simplest way to include these kinds of constraints is by using the -nl- command.
Tips: Stata - Is a Chow test the correct test to determine whether data can be pooled together?
Source: Stata FAQs by Willam Gould
A Chow test is simply a test of whether the coefficients estimated over one group of the data are equal to the coefficients estimated over another, and you would be better off to forget the word Chow and remember that definition.
History: In the days when statistical packages were not as sophisticated as they are now, testing whether coefficients were equal was not so easy. You had to write your own program, typically in FORTRAN. Chow showed a way you could perform a Wald test based on statistics that were commonly reported, and that would produce the same result as if you performed the Wald test.
Full text: here
Other related article:
How can I compute the Chow test statistic? http://www.stata.com/support/faqs/stat/chow.html
Monday, December 12, 2011
Tips - Stata: a few useful ado-related commands
Tips - Stata: the handy Stata command/function
- 'statsby', 'tabstat', 'scalar themean=r(mean)'.
- 'contrast'(How to get orthogonal polynomial coefficient), 'pwmean', 'pwcompare', and 'margins'.
- p. and q. of 'Contrast' (Orthogonal polynomials) allow to partition the effects of a factor variable into linear, quadratic, cubic, and higher-order polynomial components (I like to use p., q. assumes having equal space between groups). They are only meaningful with factor variables that have a natural ordering in the levels. For exmaple: .contrast p(2 3 4).bmigrp, noeffects
- User defined contrast of race(3 levels) and age (2 levels) without comparing the middle race group: .contrast {race#age -1 -1 0 0 1 1}
- 'destring', 'tostring','string()': Convdrting between numeric variable and string/character variable.
- 'duplicate': Report, tag, or drop duplicate observations.
- 'postfile' posts results in Stata dataset.
- ... [Contents of Stata Help]
Friday, December 02, 2011
Tips - Stata: outputting/exporting Stata results
Tips - Stata: outputting/exporting Stata results
- 'outreg2' by Roy Wada: The 'outreg2' is based on the earlier package 'outreg' but has much more features. 'outreg2' related programs include 'seeout', 'shellout', 'logout', and 'mkest'. You can use command 'ssc install [prgname]' to install these programs. For example,
- .cd \temp
- .svy, subpop(pop):logit diagdm i.survey##i.age3grp
- .margins survey##age3grp,subpop(pop) vce(svy) post
- .outreg2 using demo, stats(coef ci) paren(ci) dec(4) noaster sideway seeout replace
- 'tabout', by Ian Watson: is a table building program for oneway and twoway tables of frequencies and percentages, and for summary tables. The output from tabout matches Stata's tabulate, most of tabstat and some of table. When the 'svy' option is used, you can also get (se ci lb ub) for survey data.
- 'estout', by Ben Jann: How can I use -estout- to make regression tables that look like those in journal articles?
- 'estout' vs. 'outreg' and 'outreg2', by Roy Wada.
- 'logout', by Roy Wada: provides a fast and easy way to convert log or ASCII files into various output formats compatible with Word, Excel, LaTeX, or Stata datafile.
- 'outreg' by John Gallup: Can I make regression tables that look like those in journal articles?
- Making publication-style tables in STATA (pdf)
- How do I export tables from Stata?
- UCLA Academic Technology Services has provided much richer information on how to use Stata and other statistic software.
- Resources for learning Stata
Tuesday, November 15, 2011
Tips - Stata: How to test significance of interactions of categorical variables
Tips - Stata: How to test significance of interactions of categorical variables
We have the model
. webuse fvex
. regress y i.sex##i.group age
We can test the overall significance of the sex#group interaction by typing
. contrast sex#group
Monday, November 14, 2011
Thoughts: Education is The Key to Reduce Health Disparities
Thoughts: Education is The Key to Reduce Health Disparities
This is great. Even more, I would like to see teachers can team up to reduce disparities. My Mom’s experience tells me that the key to reduce the poverty is education, education, and still education. My Mom was a teach of elementary school in China. Sixty years ago, she went a remote poor countryside teaching not just kids but also the parents how to read. Now this area is one of the richest counties in China. My Mom is so proud of what she had done. By the way, my 80-year old Mom is still going to a senior college as a student to have fun and meet friends.
Subject: Lawyers, Doctors Team Up To Reduce Health Disparities
California Watch: Lawyers, Doctors Team Up To Reduce Health Disparities
On Kate Marr's first day practicing law at The Children's Clinic in Long Beach last week, she met with the mother of an asthmatic 7-year-old. ... The Long Beach program is the latest effort by community clinics and hospitals across the country to add lawyers to their medical teams as a way to resolve issues associated with the "social determinants of health," such as housing, domestic violence and poverty (Yeung, 11/10).
On Kate Marr's first day practicing law at The Children's Clinic in Long Beach last week, she met with the mother of an asthmatic 7-year-old. ... The Long Beach program is the latest effort by community clinics and hospitals across the country to add lawyers to their medical teams as a way to resolve issues associated with the "social determinants of health," such as housing, domestic violence and poverty (Yeung, 11/10).
Thursday, November 10, 2011
Tips - Stata: How to generate composite categorical variables and indicate/dummy variables
Tips - Stata: How to generate composite categorical variables and indicate/dummy variables, convert a continuous variable into a categorical variable
1. to generate composite categorical variables:
.egen compvar=group(var1 var2 var3), label
Now, the dataset has a categorical variable with the different combinations of three variables: var1, var2, and var3.
2. to generate indicate variables:
.tabulate compvar, generate(compvar)
Now, the dataset has multiple indicate variables with a prefix of ‘compvar’
3. to convert a continuous variable into a categorical variable
.gen agecat = recode(age, 24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
or
.gen age13grp = 1+irecode(age,24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
3. to convert a continuous variable into a categorical variable
.gen agecat = recode(age, 24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
or
.gen age13grp = 1+irecode(age,24,29,34,39,44,49,54,59,64, ///
69, 74, 79, 90) if !missing(age)
Tuesday, November 08, 2011
Tips - Stata: how to do 'lincom' after a three-way 'margins'?
Tips - Stata: how to do 'lincom' after a three-way 'margins'?
The easiest way to determine how to refer to the margins is to type
.margins, coeflegend
after the -margins- command. This will list the estimated margins as well as the _b[] notation that can be used to refer to them. Here is an example:
.webuse nhanes2, clear
.svy, subpop(female): logit highbp i.race##i.diabetes##c.age weight
.margins race, over(diabetes) at(age = (30(5)50)) subpop(female) ///
vce(svy) post
.margins, coeflegend
This tells us that if we want to compute the difference in the margins for age=30, diabetes=0, race=1 and age=35, diabetes=0, race=1, we could type
.lincom _b[1bn._at#0bn.diabetes#1bn.race] - ///
_b[2._at#0bn.diabetes#1bn.race]
-- by a senior statistician of Stata
The easiest way to determine how to refer to the margins is to type
.margins, coeflegend
after the -margins- command. This will list the estimated margins as well as the _b[] notation that can be used to refer to them. Here is an example:
.webuse nhanes2, clear
.svy, subpop(female): logit highbp i.race##i.diabetes##c.age weight
.margins race, over(diabetes) at(age = (30(5)50)) subpop(female) ///
vce(svy) post
.margins, coeflegend
This tells us that if we want to compute the difference in the margins for age=30, diabetes=0, race=1 and age=35, diabetes=0, race=1, we could type
.lincom _b[1bn._at#0bn.diabetes#1bn.race] - ///
_b[2._at#0bn.diabetes#1bn.race]
-- by a senior statistician of Stata
Thursday, November 03, 2011
Nice gadgets (freeware) from Microsoft
Nice gadgets (freeware) from Microsoft
Image Composite Editor (ICE)
This is an amazing powerful calculator has many functions with graphing options. It also has unit conversion tool.
You may also download and install Mathematics Add-In for Word and OneNote here; you can easily to plot graphs in 2D and 3D, calculate numerical results, solve equations or inequalities, and simplify algebraic expressions in your Word documents and OneNote notebooks.
Sysinternals Suite
Sysinternals Suite, a troubleshooting utility package, was bought by Microsoft a few years ago.
Final Data Collection Standards for Race, Ethnicity, Primary Language, Sex, and Disability Status Required by Section 4302 of the Affordable Care Act
HHS on Oct. 31, 2011, published final standards for data collection on race, ethnicity, sex, primary language and disability status, as required by Section 4302 of the Affordable Care Act [PDF | 1.6 MB].
The law requires that data collection standards for these measures be used, to the extent practicable, in all national population health surveys. They will apply to self-reported information only. The law also requires any data standards published by HHS comply with standards created by the Office of Management and Budget (OMB).
Proposed standards were published on June 29, 2011, and public comments were accepted until August 1, 2011.
The standards, effective upon publication today, apply to population health surveys sponsored by HHS, where respondents either self-report information or a knowledgeable person responds for all members of a household. HHS will begin implementation of these new data standards in all new surveys and at the time of major revisions to current surveys.
Friday, October 28, 2011
Wednesday, October 26, 2011
GRADE guidelines (Grades of Recommendation, Assessment, Development, and Evaluation)
GRADE guidelines (Grades of Recommendation, Assessment, Development, and Evaluation)
JCE published some systemic recommendations/guidance for rating quality of evidence and grading strength of recommendations in healthcare on two issues. I combined these related linkages below:
Tuesday, October 25, 2011
Can 'margins' be used after 'mi estimate'?
Can 'margins' be used after 'mi estimate'?
The -margins- command may not be used in the usual way after -mi estimate-. You'll need to write a short "wrapper command" that can be run with the -mi estimate- prefix. My colleagues outlined the method on Statalist: Average marginal effects for a multiply imputed complex survey. You'll want to change the 11 in the -version 11- statement to 12. One of our FAQs will also be helpful: How can I combine results other than coefficients in e(b) with multiply imputed data? - by A Statistician, Stata
Here is my modified program based on codes of UCLA Stata Portal
use http://www.ats.ucla.edu/stat/data/hsbmar, clear
/* set MI dataset */
mi set mlong
mi register imputed female math read science socst
mi svyset [pw=write], strata(ses)
mi impute chain (logit) female (regress) math read science socst ///
=ses write awards, add(10) rseed(123456)
/* program */
capture program drop mimargins
program mimargins, eclass properties(mi)
version 12
svy: logit honors i.female##i.prog read math science socst
margins female#prog, post
end
/* run the program */
mi estimate, cmdok: mimargins 1
matlist r(table)'*100, tw(20) format(%8.2f)
mi estimate (_b[1.female#2.prog]/_b[1.female#1bn.prog]): mimargins 1
Notes: The 'cmdok' option forces 'mi estimate' to estimate the current Stata unsupported model. The 'cmdok' is not necessary because of already including the 'properties(mi)' in the program.
mi estimate: svy: logit honors i.female##i.prog read math science socst
mi test 1.female#2.prog 1.female#3.prog
mi estimate (diff:1.female#2.prog-1.female#3.prog), saving(miest, replace): svy: logit honors i.female##i.prog read math science socst
mi testtransform diff
mi estimate (rdiff:1.female#2.prog/1.female#3.prog - 1) using miest
mi testtr rdiff
Useful Resources:
The -margins- command may not be used in the usual way after -mi estimate-. You'll need to write a short "wrapper command" that can be run with the -mi estimate- prefix. My colleagues outlined the method on Statalist: Average marginal effects for a multiply imputed complex survey. You'll want to change the 11 in the -version 11- statement to 12. One of our FAQs will also be helpful: How can I combine results other than coefficients in e(b) with multiply imputed data? - by A Statistician, Stata
Here is my modified program based on codes of UCLA Stata Portal
use http://www.ats.ucla.edu/stat/data/hsbmar, clear
/* set MI dataset */
mi set mlong
mi register imputed female math read science socst
mi svyset [pw=write], strata(ses)
mi impute chain (logit) female (regress) math read science socst ///
=ses write awards, add(10) rseed(123456)
/* program */
capture program drop mimargins
program mimargins, eclass properties(mi)
version 12
svy: logit honors i.female##i.prog read math science socst
margins female#prog, post
end
/* run the program */
mi estimate, cmdok: mimargins 1
matlist r(table)'*100, tw(20) format(%8.2f)
mi estimate (_b[1.female#2.prog]/_b[1.female#1bn.prog]): mimargins 1
Notes: The 'cmdok' option forces 'mi estimate' to estimate the current Stata unsupported model. The 'cmdok' is not necessary because of already including the 'properties(mi)' in the program.
mi estimate: svy: logit honors i.female##i.prog read math science socst
mi test 1.female#2.prog 1.female#3.prog
mi estimate (diff:1.female#2.prog-1.female#3.prog), saving(miest, replace): svy: logit honors i.female##i.prog read math science socst
mi testtransform diff
mi estimate (rdiff:1.female#2.prog/1.female#3.prog - 1) using miest
mi testtr rdiff
Useful Resources:
- MIMRGNS: Stata module to run margins after mi estimate
- UCLA: How can I get margins and marginsplot with multiple imputed data?
- Klein (2016): Marginal Effects in Multiply Imputed Datasets
Monday, October 24, 2011
Abramowitz and Stegun: Handbook of Mathematical Functions
“The present volume is an outgrowth of a Conference on Mathematical Tables held at Cambridge, Mass., on September 15-16, 1954, under the auspices of the National Science Foundation and the Massachusetts Institute of Technology. The purpose of the meeting was to evaluate the need for mathematical tables in the light of the availability of large scale computing machines. It was the consensus of opinion that in spite of the increasing use of the new machines the basic need for tables would continue to exist.
Numerical tables of mathematical functions are in continual demand by scientists and engineers. A greater variety of functions and higher accuracy of tabulation are now required as a result of scientific advances and, especially, of the increasing use of automatic computers. In the latter connection, the tables serve mainly for preliminary surveys of problems before programming for machine operation. For those without easy access to machines, such tables are, of course, indispensable...”
You can view or download the tenth printing of this famous reference here: http://people.math.sfu.ca/~cbm/aands/
Wednesday, October 19, 2011
How to Estimate Percentiles and Confidence Intervals
How to Estimate Percentiles and Confidence Intervals
By CDC
Including percentiles whose estimate falls on a value that is repeated multiple times in the dataset
A common practice to calculate confidence intervals from survey data is to use large-sample normal approximations. Ninety-five percent confidence intervals on point estimates of percentiles are often computed by adding and subtracting from the point estimate a quantity equal to twice its standard error. This normal approximation method may not be adequate, however, when estimating the proportion of subjects above or below a selected value, especially when the proportion is near 0.0 or 1.0 or when the effective sample size is small. In addition, confidence intervals on proportions deviating from 0.5 are not theoretically expected to be symmetric around the point estimate. Further, adding and subtracting a multiple of the standard error to an estimate near 0.0 or 1.0 can lead to impossible confidence limits (i.e., proportion estimates below 0.0 or above 1.0). The approach used for the Report data tables (and for previous Reports) produces asymmetric confidence intervals consistent with skewed (nonnormal) biologic data distributions. ...
You can read the whole article here: http://www.cdc.gov/exposurereport/data_tables/appendix_a.html
By CDC
Including percentiles whose estimate falls on a value that is repeated multiple times in the dataset
A common practice to calculate confidence intervals from survey data is to use large-sample normal approximations. Ninety-five percent confidence intervals on point estimates of percentiles are often computed by adding and subtracting from the point estimate a quantity equal to twice its standard error. This normal approximation method may not be adequate, however, when estimating the proportion of subjects above or below a selected value, especially when the proportion is near 0.0 or 1.0 or when the effective sample size is small. In addition, confidence intervals on proportions deviating from 0.5 are not theoretically expected to be symmetric around the point estimate. Further, adding and subtracting a multiple of the standard error to an estimate near 0.0 or 1.0 can lead to impossible confidence limits (i.e., proportion estimates below 0.0 or above 1.0). The approach used for the Report data tables (and for previous Reports) produces asymmetric confidence intervals consistent with skewed (nonnormal) biologic data distributions. ...
You can read the whole article here: http://www.cdc.gov/exposurereport/data_tables/appendix_a.html
Tuesday, October 18, 2011
The 2009 ISPAD Clinical Practice Consensus Guidelines
The 2009 Clinical Practice Consensus Guidelines
By the International Society for Pediatric and Adolescent Diabetes
Here are the PDFs of chapters:
By the International Society for Pediatric and Adolescent Diabetes
Here are the PDFs of chapters:
Monday, October 17, 2011
Recipes and Meal Planning from the American Diabetes Association
Recipes and Meal Planning from the American Diabetes Association
If you are looking for healthy recipes to lose weight, prevent, or manager diabetes, you may like the MyFoodAdvisor – Recipes for healthy Living from the American Diabetes Association. You must register to access these recipes, which I don’t like the way of access, but it’s FREE.
If you are looking for healthy recipes to lose weight, prevent, or manager diabetes, you may like the MyFoodAdvisor – Recipes for healthy Living from the American Diabetes Association. You must register to access these recipes, which I don’t like the way of access, but it’s FREE.
Wednesday, October 12, 2011
Top 50 Statistics Blogs of 2011
The Best Colleges has published a long list of statistic related blogs. Wish they could have reduced the number to 10.
Thursday, October 06, 2011
Steve Jobs' Inspirational Advice
Steve Jobs' Inspirational Advice
- Stay Hungry, Stay Foolish (2008)
- Steve Jobs on Wikipedia
- Transcript of Commencement Speech at Stanford given by Steve Jobs
- A Collection of 60 Inspirational Steve Jobs Quotes About Life, Design and Apple
- Steve Jobs's Best Quotes on the WSJ Blogs
- The 11 Best Steve Jobs Quotes: Remembering The Apple CEO
- The 13 Most Memorable Quotes From Steve Jobs
- Read more on Business Insider
- Steve Jobs's quotes on Wikiquote
- in Chinese 乔布斯十条经典语录
Monday, October 03, 2011
Tips: SAS code matched to Stata code and others
Usually, I think that SAS is an analog to a product of Microsoft, Stata is an analog to a product of Apple, and R is an analog to a product of Google. I have used the SAS for many years, but have been attracted by Stata for some new features. I am always trying to find the same handy data management features using Stata, and notice there are a few websites providing these equivalents.
- On the Stata website of Carolina Population Center, UNC, there are a nice webpage displaying the equivalent command of Stata and SAS. It shows how to "Do" in Stata what you know how to "Program" in SAS. , or read this PDF file
- UCLA also provides a similar page here
- Stata tutorials: UCLA, Princeton University online Stata tutorial
- Statistic test overview
- Biostatistics by William D. Dupont
- Stata tips by Michael Norman Mitchell
Resources for Disability Research
- The Future of Disability in America. You can download the document for free. This report affirms the ICF as a model for disability research, and it summarizes some of the broad themes in disability.
- Workshop on Disability in America. This free book contains 14 commissioned essays on disability—ranging from models of disability (Whiteneck) to trends in youth, working age, and older people.
- Improving measurement of late Life Disability
- Prevalence of Complex Activity Limitations, an example of CAL, using US National Health Interview Survey (NHIS)
- these materials highly recommended by my colleague J.C., an expert in this disability area.
Monday, September 19, 2011
How to get orthogonal polynomial coefficient/vector/codes
Tips - R & Stata & SAS: How to get orthogonal polynomial coefficient/vector/codes
When we do "contrast {lvl #1 #2 #3}" for trend analyses using Stata or other software for unequally spaced levels/categories, we need the orthogonal polynomial coefficient (#1 #2 #3), which is hard to be find in books. We can get these coefficients using R, Stata, or SAS. My favorite software for this purpose is R. Below I show the examples using these different kinds of software. Note: Stata has an operator (p. for orthogonal polynomial in the level values) for unequally spaced levels, for example, "contrast p.lvl".
R
mostly I use R to get these coefficients:
>cntr<-poly(c(1,2,5,6),3)
>cntr
Stata
Step 1: create a dataset with one variable [lvl]:
.input lvl
1. 1
2. 2
3. 5
4. 6
5. end
Step 2-b: use 'orthpoly'
.orthpoly lvl, generate(cntr1 cntr2 cntr3) degree(3)
Now, in the dataset, you can find three new variables 'cntr1' for the orthogonal polynomial coefficients of degree 1 (linear), and 'cntr2' for the orthogonal polynomial coefficients of degree 2 (quadratic), and 'cntr3' for the orthogonal polynomial coefficients of degree 3 (cubic).
SAS
PROC IML;
lvl = {1 3 5 6}
cntrl=ORPOL(lvl);
PRINT cntrl;
QUIT;
When we do "contrast {lvl #1 #2 #3}" for trend analyses using Stata or other software for unequally spaced levels/categories, we need the orthogonal polynomial coefficient (#1 #2 #3), which is hard to be find in books. We can get these coefficients using R, Stata, or SAS. My favorite software for this purpose is R. Below I show the examples using these different kinds of software. Note: Stata has an operator (p. for orthogonal polynomial in the level values) for unequally spaced levels, for example, "contrast p.lvl".
R
mostly I use R to get these coefficients:
>cntr<-poly(c(1,2,5,6),3)
>cntr
Stata
Step 1: create a dataset with one variable [lvl]:
.input lvl
1. 1
2. 2
3. 5
4. 6
5. end
Step 2-b: use 'orthpoly'
.orthpoly lvl, generate(cntr1 cntr2 cntr3) degree(3)
Now, in the dataset, you can find three new variables 'cntr1' for the orthogonal polynomial coefficients of degree 1 (linear), and 'cntr2' for the orthogonal polynomial coefficients of degree 2 (quadratic), and 'cntr3' for the orthogonal polynomial coefficients of degree 3 (cubic).
SAS
PROC IML;
lvl = {1 3 5 6}
cntrl=ORPOL(lvl);
PRINT cntrl;
QUIT;
Friday, September 16, 2011
Tips: Stata - my first Stata program
capture program drop tabm
program tabm
version 12
syntax varlist [if][in],cell count column row se ci ///
cv percent proportion]
local varnum : word count `varlist'
local x : word 1 of `varlist'
forvalues i=2/`varnum' {
local y: word `i' of `varlist'
svy: tabulate `x' `y',`col' `cell' `se' `percent' ///
format(%5.1f)
}
end
.tabm sex race5grp diabetes,cell se percent
capture program drop tabm
program tabm
version 12
syntax varlist [if][in],cell count column row se ci ///
cv percent proportion]
local varnum : word count `varlist'
local x : word 1 of `varlist'
forvalues i=2/`varnum' {
local y: word `i' of `varlist'
svy: tabulate `x' `y',`col' `cell' `se' `percent' ///
format(%5.1f)
}
end
.tabm sex race5grp diabetes,cell se percent
why I get error message, when using 'margins' for complex sampling data
Tips - Stata: why I get error message, when using 'margins' for complex sampling data
When I use 'margins' for complex sampling data, after a logistic regression:
I've got an error message sometime:
"missing predicted values encountered within the estimation sample r(322)"
The answer is to include 'subpop' in the 'margins' command:
.margins diabetes, subpop(if suball==1) vce(unconditional) post
When I use 'margins' for complex sampling data, after a logistic regression:
. svy, subpop(if suball==1): logit arthritis i.diabetes c.age i.sex i.bmi4grp
. margins diabetes, vce(unconditional) post
. margins diabetes, vce(unconditional) post
I've got an error message sometime:
"missing predicted values encountered within the estimation sample r(322)"
The answer is to include 'subpop' in the 'margins' command:
.margins diabetes, subpop(if suball==1) vce(unconditional) post
Subscribe to:
Posts (Atom)