Statalist The Stata Listserver


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

Re: st: Error message "type mismatch"


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Error message "type mismatch"
Date   Thu, 19 Jan 2006 14:32:49 +0900

Ying Wang wrote:

I transfered my data from long to wide, and thus have continuous variables
like obrum1 through obrum10. I want to add the values of each obrum*
variable together. I am trying to use the command egen
obrumtot=rowtotal(obrum1-obrum10).

However, it keeps giving me an error message "type mismatch". I looked
into those 10 vars. The storage type of obrum1 and obrum2 is int., and
that of the rest is byte. Does this have some say on the error message?

I also tried to use recast to set the int. to byte., but it didn't seem to
be working.

I have done some research and didn't have any luck. Can anybody kindly
suggest me how to deal with this?

--------------------------------------------------------------------------------

-egen . . . rowtotal()- doesn't mind a mixture of int and byte (see below),
so that isn't your problem.  You use the variable list shorthand,
obrum1-obrum10.  This will include all variables between obrum1 and obrum10;
check to make sure that you don't have a string variable in the middle of
that list (see below).  Consider using obrum* instead for the varlist
shorthand:  -egen int obrumtot = rowtotal(obrum*).

Joseph Coveney

. clear

. set more off

. set seed `=date("2006-01-19", "ymd")'

. set obs 10
obs was 0, now 10

. forvalues i = 1/2 {
  2.     generate int var`i' = floor(1000 * uniform())
  3. }

. forvalues i = 3/10 {
  2.     generate byte var`i' = 100 * uniform()
  3. }

. egen vartot = rowtotal(var1-var10)

. set linesize 72

. slist in 1/2, noobs // No problem

var1  var2  var3  var4  var5  var6  var7  var8  var9  var10  vartot
 221   291    80    70    34    17    31    86    13      8     851
 809   837    44    31     4    86    36    50    76     20    1993

. drop vartot

. generate str itsme = "Hi there!"

. order var1 itsme

. capture noisily egen vartot = rowtotal(var1-var10) // Problem here
type mismatch

. egen vartot = rowtotal(var*)

. slist in 1/2, noobs // No problem

var1      itsme  var2  var3  var4  var5  var6  var7  var8  var9  var10
 221  Hi there!   291    80    70    34    17    31    86    13      8
 809  Hi there!   837    44    31     4    86    36    50    76     20

vartot
   851
  1993

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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