Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: using the 'real' command


From   [email protected]
To   [email protected]
Subject   Re: st: RE: using the 'real' command
Date   Wed, 8 Dec 2004 14:28:42 -0500

Nick,

thank you for your prompt reply. yes, it appears i neglected to put the
delimiter ... it works fine now but I still have my original problem of forcing
the display format to be %2.0f.

here is the context: I am working with a household survery on child labor force.
I am trying to generate a unique id by concatenating a few string variables. the
reason I am creating the unique id is so that i can merge the data set with
anoterh survey on labor force from the same country.  The variables (cl01 thru
cl08) originally came in numeric format (with a display format of %2.0f). What I
am trying to do is convert these variables to string variables while keeping the
display format.

unfortunately, the display format that I get when i convert to string is %9.s

this is what my do file looks like:

tostring cl01-cl08, replace force;
gen id1=real(cl01); format id1 %02.0f;
gen id2=real(cl02); format id2 %02.0f;
gen id3=real(cl03); format id3 %02.0f;
gen id4=real(cl04); format id4 %02.0f;
gen id5=real(cl05); format id5 %02.0f;
gen id6=real(cl06); format id6 %03.0f;
gen id7=real(cl07); format id7 %02.0f;
gen id8=real(cl08); format id8 %02.0f;
tostring id1-id8, replace usedisplayformat;
egen hhid=concat(id1 id2 id3 id4 id5 id6 id7 id8);

any advice is appreciated

M
Mirafe Gebriel Marcos



                                                                                                                                           
                      "Nick Cox"                                                                                                           
                      <[email protected]>           To:       <[email protected]>                                          
                      Sent by:                         cc:                                                                                 
                      owner-statalist@hsphsun2.        Subject:  st: RE: using the 'real' command                                          
                      harvard.edu                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      12/08/2004 01:19 PM                                                                                                  
                      Please respond to                                                                                                    
                      statalist                                                                                                            
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           




You _need_ the () to invoke the -real()- function
(it's not a command).

Your code is not obviously illegal, assuming
a prior

#delimit ;

and a posterior

;

I guess we need more context to comment helpfully.

Nick
[email protected]

[email protected]

> I am trying to convert a string variable to a numeric
> variable so that I can
> specify the display format, but I get an error message saying
> it can't recognize
> the ( ), i.e., the parenthesis. can anyone help?
>
> gen id1=real(cl01); format id1 %02.0f

*
*   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/




*
*   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