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: factor variables vs xi
From
Richard Palmer-Jones <[email protected]>
To
[email protected]
Subject
st: factor variables vs xi
Date
Thu, 24 May 2012 12:00:54 +0100
Dear Readers
I came across a problem using factor variables (with the prais comand).
I am wondering if the problem is that the problem occurs because the
variable from which you wish to produce factors has laerge numeric
values the i.var code fails even though it works with the older xi
i.var code and when I recode the large values to smallere ones.
I can't reproduce this using auto.dta so here are sections of the output.
* using xi
xi i.vilcd i.year
. .vilcd _Ivilcd_330603001-332708149(naturally coded;
_Ivilcd_330603001 omitted)
. i.year _Iyear_2002-2007 (naturally coded; _Iyear_2002 omitted)
prais depvar .... _Iyear_* Ivilcd_* .....
[output]
_Iyear_2003 | -.3848006 .1138329 -3.38 0.001 -.6079923 -.161609
_Iyear_2004 | -.1880117 .0858427 -2.19 0.029 -.3563231 -.0197003
_Iyear_2005 | -.224122 .0593118 -3.78 0.000 -.3404144 -.1078295
_Iyear_2006 | -.2366355 .0360867 -6.56 0.000 -.3073905 -.1658805
_Iyear_2007 | 0 (omitted)
....
_Ivilcd_330603003 | 13.83685 6.157102 2.25 0.025
1.764646 25.90906
_Ivilcd_330603004 | 11.0135 5.747892 1.92 0.055
-.2563655 22.28337
_Ivilcd_330603005 | -2.277502 47.13286 -0.05 0.961
-94.69072 90.13571
_Ivilcd_330603006 | 5.394073 14.7922 0.36 0.715
-23.60894 34.39709
_
* using factor variables
. prais depvar .... i.year i.vilcd ...> lndist distyear
[output]
....
year |
2004 | .1021677 .0276891 3.69 0.000 .0478827 .1564528
2005 | -.0220684 .051486 -0.43 0.668 -.1230076 .0788708
2006 | -.1549629 .0745452 -2.08 0.038 -.3011101 -.0088157
2007 | -.1560546 .0948655 -1.65 0.100 -.3420401 .029931
....
vilcd |
330603003 | 0 (omitted)
330603004 | 0 (omitted)
330603005 | 0 (omitted)
330603006 | 0 (omitted)
* vilcd does not work with factor variables ?cos values too large?
gen villn = .
qui tab vilcd, matrow(row) matcell(cell)
forval i = 1/`r(r)' {
qui replace villn = `i' if row[`i', 1] == vilcd
}
prais depvar .... i.year i.villn ....> lndist distyear
[output]
....
year |
2004 | .1967895 .0342813 5.74 0.000 .1295743 .2640047
2005 | .1606798 .061101 2.63 0.009 .0408793 .2804804
2006 | .1481668 .0886042 1.67 0.095 -.0255591 .3218928
2007 | .3848028 .113833 3.38 0.001 .1616109 .6079946
.....
villn |
2 | 13.83682 6.157102 2.25 0.025 1.764615 25.90903
3 | 11.01349 5.747892 1.92 0.055 -.2563812 22.28336
4 | -2.277797 47.13286 -0.05 0.961 -94.69101 90.13542
5 | 5.39397 14.7922 0.36 0.715 -23.60905 34.39699
6 | 18.0429 19.47698 0.93 0.354 -20.14554 56.23134
7 | 19.83282 9.599951 2.07 0.039 1.010231 38.65541
.....
I took me a little time to work out "the" soultion, but it may be of
help to others
Cheers
Richard
*
* 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/