Announcement

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

  • Replace ZEROS

    How to replace empty cells and Infinity cells with zero in the entire dataset at once? Well thank you.

  • #2
    Pepe:
    welcome to this forum.
    If your data are in numeric format (as far as empty cells are concerned; I do not know how Stata codes -Infinity- in numerical format):
    Code:
    replace yourvar=0 if yourvar==.
    If your variable is in -string- format:
    Code:
    . replace yourvar="0" if yourvar=="Infinity" | yourvar=="."
    
    . destring yourvar, g(num_yourvar)
    yourvar: all characters numeric; num_yourvar generated as byte
    
    . list
    
         +--------------------+
         | yourvar   num_yo~r |
         |--------------------|
      1. |       0          0 |
      2. |       0          0 |
         +--------------------+
    
    .
    See also -foreach-.
    Last edited by Carlo Lazzaro; 23 Feb 2023, 04:56.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      See also

      Code:
      help mvencode

      Comment

      Working...
      X