Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: RE thread: SEM with categorical variables
From
William Buchanan <[email protected]>
To
[email protected]
Subject
Re: st: RE thread: SEM with categorical variables
Date
Wed, 13 Mar 2013 08:20:09 -0700
You've not mentioned what stops working and/or where it stops working. You have something in a .do file, which is a mystery to everyone but you and then you clear the memory. If the problem is the set obs issue at the end of your post, this has been addressed several times elsewhere on the Statalist (from what I remember you need to use a scalar with the number and not a local macro).
HTH,
Billy
On Mar 13, 2013, at 8:06 AM, Laura Maria Schwirz <[email protected]> wrote:
> Thanks for quick reply. It actually works up to a certain point..
> local thevars hewsonstrong hewsonknowo hewsonint hewsoninspi
> hewsonmoral hewsoncom hewsondecent hewsondepend hewsonrel hewsonsens
>
> . polychoric `thevars'
>
> Polychoric correlation matrix
>
> (output omitted)
>
> . mat polychR = r(R)
>
> . forvalues i=1/`: word count `thevars' ' {
> 2. forvalues j=1/`i' {
> 3. local setcor `setcor' `=polychR[`i',`j']'
> 4. }
> 5. if `i' < `: word count `thevars' ' local setcor `setcor' \
> 6. }
>
> . local N = _N
>
> .
> end of do-file
>
> . do "/var/folders/lw/lweDBBEGH68nFpOhV2D+gk+++TI/-Tmp-//SD00459.000000"
>
> . clear
>
> . ssd init hewsonstrong hewsonknowo hewsonint hewsoninspi hewsonmoral
> hewsoncom hewsondecent hewsonde
>> pend hewsonrel hewsonsens
>
> Summary statistics data initialized. Next use, in any order,
>
> ssd set observations (required)
> It is best to do this first.
>
> ssd set means (optional)
> Default setting is 0.
>
> ssd set variances or ssd set sd (optional)
> Use this only if you have set or will set correlations and,
> even then, this is optional but
> highly recommended. Default setting is 1.
>
> ssd set covariances or ssd set correlations (required)
>
> . ssd set obs `N'
> number required
> r(100);
>
> Once I run the 'clear' command, it stops working.
>
> Many thanks for your help, much appreciated.
>
> Laura
>
>
> On 13 March 2013 14:42, William Buchanan <[email protected]> wrote:
>>
>> I don't think it's a problem with Stas's code:
>>
>> clear
>> set obs 1000
>> set seed 123412345
>> loc thevars hewsonstrong hewsonknowo hewsonint hewsoninspi hewsonmoral hewsoncom hewsondecent hewsondepend hewsonrel hewsonsens
>> foreach v of loc thevars {
>> qui: g id=runiform()
>> qui: sort id
>> /* Create categorical variables */
>> qui: egen `v' = cut(id), group(5)
>> /* Recode the variables to have a scale of 1-5 */
>> qui: replace `v'=`v'+1
>> qui: drop id
>> ta `v'
>> }
>> di `"`thevars'"'
>> polychoric `thevars'
>>
>> You should get the matrix below:
>>
>> hewsonstrong hewsonknowo hewsonint hewsoninspi hewsonmoral hewsoncom hewsondecent hewsondepend hewsonrel hewsonsens
>> hewsonstrong 1
>> hewsonknowo .00757784 1
>> hewsonint -.01262061 -.02690757 1
>> hewsoninspi -.02231892 .00686848 -.05248286 1
>> hewsonmoral -.01757277 .03654591 -.01172315 .00876538 1
>> hewsoncom .02118915 -.01551056 -.01772426 -.00254414 -.01837419 1
>> hewsondecent -.04116923 .01386142 .01676589 .02919821 .02132269 -.03298761 1
>> hewsondepend -.05280085 -.04659978 .04573638 .01585641 .06480197 -.01835768 -.02216604 1
>> hewsonrel .02682836 -.00184872 -.00382025 .01606113 -.03550408 -.0348673 .06411171 -.02613873 1
>> hewsonsens .02954704 -.0527784 .01723573 -.06313792 .00313384 .01654635 .02302709 -.00659043 -.0318338 1
>>
>>
>>
>>
>> On Mar 13, 2013, at 7:21 AM, Laura Maria Schwirz <[email protected]> wrote:
>>
>>> I am referring to a previous thread (RE: sem with categorical
>>> variables, September 2012) as I have similar problems. I tried using
>>> Stas' code for polychoric to sem analysis but the local command
>>> appears to be a problem. If I type
>>>
>>>> local thevars hewsonstrong hewsonknowo hewsonint hewsoninspi hewsonmoral hewsoncom hewsondecent hewsondepend hewsonrel hewsonsens
>>>> display `thevars'
>>>> polychoric `thevars'
>>> varlist required
>>>
>>> It as actually empty so i can't proceed with the polychor command
>>> Any thoughts/ideas of where I am going wrong?
>>>
>>> Thanks,
>>> Laura
>>> *
>>> * For searches and help try:
>>> * http://www.stata.com/help.cgi?search
>>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
>> * http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
> --
> Laura Schwirz
>
> PhD Candidate and IRCHSS Scholar
> Department of Political Science
> Trinity College Dublin
> Dublin 2
> Republic of Ireland
> Email: [email protected]
>
>
>
> --
> Laura Schwirz
>
> PhD Candidate and IRCHSS Scholar
> Department of Political Science
> Trinity College Dublin
> Dublin 2
> Republic of Ireland
> Email: [email protected]
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/