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]
st: comformability error
From
Violeta Carrion <[email protected]>
To
[email protected]
Subject
st: comformability error
Date
Mon, 5 Nov 2012 11:21:08 -0600
Greetings...
I am new to manipulating matrices in the sense of trying to reproduce
a tailored output from what Stata would typically generate. I have a
situation with a large number of variables over a longitudinal scheme
over different weighs for a complex survey situation. I am trying to
label the rows of the output matrix such that a very large output is
more readable. What I think is happening is that on the cases where a
variable has 4 labels instead of 3 the matrix sizes mismatch and fails
due to the comformabilty error. Yet due to my lack of experience I am
not fully convinced of this either. I have not been able to muster a
solution and was looking for any suggestions which would be hightly
appreciated.
The code below is an extraction for 2 variables of the larger syntax
file. Below this, there is the output Stata generates with the error.
The variables have a multiword labels. For my purposes it will suffice
if I label the row matrices with the numeric values for each variable.
Thanks for your time and help!, Violeta Carrion, Chicago
*==============================================================================
capture program drop getnumbers
program getnumbers
* getnumbers YEAR K gradelevelnum variable
capture noisily confirm matrix e(Col)
if !_rc {
di in yellow " R:`e(rowvar)' C:`e(colvar)' Yr:`1'
W:`e(wvar)' G:`2' subpop: `3'"
*di e(cmdline)
mat define newprop = e(Prop)
*mat list e(Prop)
mat colnames newprop = `:colnames e(Col)'
*mat rownames newprop = `:colnames e(Row)'
*mat list newprop
*----->>>>>>>>>>> mat rownames newprop = `:colnames e(Row)'
/*<-problem line. */
mat u = J(rowsof(matrix(e(Prop))),1,1)
*mat list u
mat c = u'*e(Prop)
*mat list c
*---------------
matrix f = J(rowsof(matrix(e(Prop))),colsof(c),0)
*matrix list f
levelsof `4', local(rlevels) /*<-problem line. */
local nr=rowsof(matrix(e(Prop)))
local nc=colsof(c)
di in red "`nr' `nc'"
mat rownames f = `rlevels'
mat colnames f = `:colnames e(Col)'
*---------------
forvalues rn = 1/`nr' {
forvalues cn = 1/`nc' {
matrix f[`rn',`cn']= (newprop[`rn',`cn']/c[1,`cn']) *100
}
}
matrix list f
di "p ..................................................................
`e(p_Pear)'"
*----------reset
matrix drop f
matrix drop u
matrix drop c
matrix drop newprop
local nc=0
local nr=0
}
else {
di in red "NO DATA available.... R:`4' C:`demovar' Yr:`1'
W:`e(wvar)' G:`2' subpop: `3'"
capture matrix drop newprop
}
end
svyset psu [pw=distnrwgt_d], strata(stratum) fpc(d_fpc)
forvalues yr=1(1)5 {
capture quietly svy, subpop(if dist_3==1): tab ng9r region if
gradelevelnumeric==1 & year==`yr', percent col format(%7.2f)
stubwidth(35)
getnumbers "`yr'" "1" "dist_3" ng9r
capture quietly svy, subpop(if dist_3==1): tab ng10r region if
gradelevelnumeric==1 & year==`yr', percent col format(%7.2f)
stubwidth(35)
getnumbers "`yr'" "1" "dist_3" ng10r
}
exit
*===================== same code but being runned....
svyset psu [pw=distnrwgt_d], strata(stratum) fpc(d_fpc)
pweight: distnrwgt_d
VCE: linearized
Single unit: missing
Strata 1: stratum
SU 1: psu
FPC 1: d_fpc
.
. forvalues yr=1(1)5 {
2. capture quietly svy, subpop(if dist_3==1): tab ng9r region if
gradelevelnumeric==1 & year==`yr', percent col format(%7.2f)
stubwidth(35)
3. getnumbers "`yr'" "1" "dist_3" ng9r
4. capture quietly svy, subpop(if dist_3==1): tab ng10r region if
gradelevelnumeric==1 & year==`yr', percent col format(%7.2f)
stubwidth(35)
5. getnumbers "`yr'" "1" "dist_3" ng10r
6. }
R:ng9r C:region Yr:1 W:distnrwgt_d G:1 subpop: dist_3
0 1 2
3 4
f[3,4]
west midwest south northeas
0 86.956795 92.829315 91.977746 76.572976
1 7.1904915 1.4491433 .36791124 1.6357844
2 5.852714 5.721542 7.6543424 21.79124
p ..................................................................
.0014410953062435
R:ng10r C:region Yr:1 W:distnrwgt_d G:1 subpop: dist_3
0 1 2 4
3 4
conformability error
r(503);
end of do-file
r(503);
. matrix list e(Col)
e(Col)[1,4]
west midwest south northeas
r1 1 2 3 4
. labellist ng10r
ng10r:
0 no policy or provision
1 Weak policy
2 strong policy
4 bans vending machines or all competitive foods & beverages
.g grade level NA
*
* 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/