Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • To convert 'blue digit ' column into 'black digit' column (string to normal variable)

    Hi.
    I am using a data set which contains more than 600,000 observations on household expenditure.

    The household expenditure varibale is " nf_value" which is string. (appeared in red color )

    Then I coverted it into numeric using 'destring command' and named as "expend". (digits changed into blue color )

    However, stils I can not do any mathematical operations correctly using "expend"

    (I think it is beacuse some 'lable values' assinged to each cell.)

    Can anybody help me to convert this 'blue digit column' in to 'black digit column'.; simply to normal integer or byte variable?
    psu a0 snumber hhno nhh result nf_code nf_value expend
    39 96375 1 1 1 1 2001 400 400
    39 96375 1 1 1 1 2002 48 48
    39 96375 1 1 1 1 2003 87 87
    39 96375 1 1 1 1 2101 350 350

  • #2
    We need an example that allows us to exactly reproduce your problem. You tried to give us such an example, but that shows us what you want as an end result, not what you have. To give us what you have you can use the dataex command, as is discussed in the FAQ (black bar near the top of this page). You also need to give us the exact thing you typed, just saying which command you think you used is not enough. With problems like these, the devil is in the details, so without details we cannot answer your question.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi,
      Thank you Mr Maarten,

      Actually I want to summarize 'expend' variable that represent household expenditure for different expenditure items based on 'nf-code' variable.

      For example, I need to summarize 400, 48, 87 in the 'expend' variable, using 'nf_code'; 2001, 2002, 2003

      I will use following command:


      collapse (sum) expend if inrange( nf_code , 2001, 2004) , by(psu a0 snumber hhno nhh result)



      when I do this, the total should be 535 (which is sum of 400+48+87). However I get wrong answer.


      Thanks in advance.





      Comment


      • #4
        OK, that is a start, but you still have not given us the data example.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Then I coverted it into numeric using 'destring command' and named as "expend". (digits changed into blue color )
          If the values of expend viewed in Stata's Data Editor appear as blue, then you did not use the destring command, you used the encode command, and that was a mistake.

          The encode command is designed for assigning numerical codes to non-numeric strings like "France", "Germany", "United States". The output of help encode instructs us

          Do not use encode if varname contains numbers that merely happen to be stored as strings; instead, use generate newvar = real(varname) or destring; see real() or [D] destring.
          So drop your current expend variable and recreate it using the destring command.
          Last edited by William Lisowski; 05 May 2021, 07:17.

          Comment


          • #6
            Hi Mr William,
            Yes, you are right. I made a mistake. I used the 'encode command' instead 'Destring'.
            Thank you so much for all the help.
            I did as you suggested, and it worked.






            Comment

            Working...
            X