Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: corr_svy & covariance matrix for survey data


From   Ishtar Govia <[email protected]>
To   [email protected]
Subject   Re: st: corr_svy & covariance matrix for survey data
Date   Fri, 3 Oct 2008 07:12:13 -0500

Thanks for the advice, Steven. I ran the code using the auto dataset as you suggested. Your explanations and running the code myself using the auto dataset helped me understand better now what each command did. I'll be trying it on my own data later today.

Thanks again!


On Oct 3, 2008, at 3:09 AM, Steven Samuels wrote:


You should run the code to see what it is does, Ishtar. You can put -display- and -list- commands to see what it is happening. The final result is a list of nine covariances. You may have to cut and paste from the list of covariances by hand into your other applications. I'm not too conversant with Stata's matrix language, but instead of the "vec" function, I could have written: matrix clist = e(b)' ('= transpose operator). Look up -help- matrix, which may give you some ideas for converting the vector into a matrix. If you are only transferring one covariance matrix, creating it by hand and feeding it into the other applications may be the easiest approach.

On Oct 3, 2008, at 12:16 AM, Ishtar Govia wrote:


Many thanks for sending along the code, Steve. Can you provide some explanation for some lines of the code so that I can understand better what exactly I would be doing to get the matrix?

Specifically, why am I only standardizing the weight variable?
"weight" is a variable in the system "auto" data set; it is not the survey weight variable, set in the -pweight- option. After the - sysuse- statement, -des- the data set and -sum- it to look at it. I chose that data set because everybody has it. However it is not really a survey data set, so it is necessary to pretend that it is, and therefore I chose one of the variables to act as the survey - pweight-. If you do not understand the -svyset- statement, consult the -help-.

Why divide by 1000? Without dividing by 100, some of the covariance terms and covariances involving the weight variable will be very large; see what happens to the results if you run the code and don't divide.


Should I also be standardizing the cluster and stratum variable?
No--there are no computations involving them.

What exactly do the "w" and the "v" in the code to generate the n^2 covariance terms mean/represent?
`v' and `w' are place-holders which take on the names of the variables. There is no rule about how to name them, but short is good; I could have used "x" and "y'. Look up -foreach-.

The number of covariance terms is not n^2, as I wrote, but p^2, where "p" is the number of variables. In the example, 3^2=9 terms are generated. You can -list- them and -summarize- them. It is their means which are the estimated covariances themselves.



What would I be doing exactly in the format c_* %20.5fc line of the code and why does that number change in the code to get the covariance? (i.e. format c_* %15.5fc)

Some of the covariances are large, so it is necessary to give them room to display without going to exponential notation.I included two format statements by mistake. You can omit either one of them. Look up "help format"



On Oct 2, 2008, at 1:50 PM, Steven Samuels wrote:

In addition, does anyone know how to use the matrix I am trying to obtain above to obtain a covariance matrix that can be easily transferred to Mplus or LISREL for CFA and SEM analyses?

In Stata V 10 Version 10.1 corr_svy does not return the proper correlation matrix, at least for p>2 dimensions.

The following code should get you the covariance matrix in a list. I don't know anything about the programs you want to feed into, so you will have to manipulate the list yourself to suit their requirements.

********************* CODE BEGINS**********************
* Create covariance matrix for survey data
*******************************************************
sysuse auto,clear
svyset _n [pweight=rep78]
gen wt000=weight/1000 //standardize to avoid large values

********************************************************
* put variables into a macro
*******************************************************
local cvars mpg wt000 trunk

*******************************************************
* Get means
*******************************************************
svy: mean `cvars' //outputs weighted means in _b[varname]


*******************************************************
* Get n^2 covariance terms
*******************************************************
foreach w of varlist `cvars' {
foreach v of varlist `cvars' {
gen c_`w'_`v' = ((`w' - _b[`w'])^2)*((`v' - _b[`v'])^2)
}
}

format c_* %20.5fc

*******************************************************
* Get Covariances
*******************************************************
svy: mean c_*
format c_* %15.5fc

matrix clist = vec(e(b))
matrix list clist
*****************CODE ENDS*************************







On Oct 1, 2008, at 9:57 PM, Ishtar Govia wrote:


Dear List,

I am using Stata 10/SE 10.1 for Macs. I have two questions. One concerning the --corr_svy-- module and error messages I have been getting, the second concerning how to obtain a covariance matrix for complex survey sample data, within Stata.

I am working with a complex survey sample dataset and am using Stata for some preliminary data analyses (univariate and multivariate checks for normality, efas) before moving to Mplus for SEM modeling. I installed the --corr_svy-- module from within Stata by typing "ssc install corr_svy"

However, in my first attempt below, I got the following error message:

svy, subpop (if race3cat==2 & sex==1 & (riwyes==1 & riwyes <.)): corr_svy lesscurt lessresp poorserv notsmart actfraid thkdisho actbettr callnmes trethara follstor, pw obs sig

corr_svy is not supported by svy with vce(linearized); see help svy estimation for a list of Stata estimation commands that are supported by svy
r(322);

I then attempted to reset the weight and design variables, and run the --corr_svy--, following the example in the "help" for the --corr_svy--, excluding my subpop specification.

. svyset clust [pweight=wgtcentriw], strata (stratum) ||_n
Note: stage 1 is sampled with replacement; all further stages will be ignored

pweight: wgtcentriw
VCE: linearized
Single unit: missing
Strata 1: stratum
SU 1: clust
FPC 1: <zero>

. corr_svy lesscurt lessresp poorserv notsmart actfraid thkdisho actbettr callnmes trethara follstor, pw obs sig

This worked--but it didn't include my subpop specification. I then tried the same thing with my subpop specifcation and it DIDN'T work. Any ideas on how to use the corr_svy module to obtain the correlation matrix, accounting for the weight and design variables and allowing me to restrict my analyses to my subpop of interest?

corr_svy lesscurt lessresp poorserv notsmart actfraid thkdisho actbettr callnmes trethara follstor [pweight=wgtcent], strata(stratum) psu(clust) subpop(if race3cat==2 & sex==1 & (riwyes==1 & riwyes <.)) pw obs sig print(10) star(5)

subpop() does not contain a valid varname
r(198);

. svyset clust [pweight=wgtcentriw], strata (stratum) ||_n
Note: stage 1 is sampled with replacement; all further stages will be ignored

pweight: wgtcentriw
VCE: linearized
Single unit: missing
Strata 1: stratum
SU 1: clust
FPC 1: <zero>

. corr_svy lesscurt lessresp poorserv notsmart actfraid thkdisho actbettr callnmes trethara follstor, pw obs sig


In addition, does anyone know how to use the matrix I am trying to obtain above to obtain a covariance matrix that can be easily transferred to Mplus or LISREL for CFA and SEM analyses?

Thanks for your consideration,

Ishtar Govia
[email protected]

*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index