Announcement

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

  • Assigning a result from summarize to a variable

    Hi everyone,

    I want to sum a variable and then assign its highest value +1 to an observation. The variable is called cluster and when I summarize it, max=2412. The observation is identified by the town_code 1997.
    I tried to do this using (variable names are inclinated):

    sum cluster
    replace cluster= ( r(max) + 1 ) if town_code==1997

    But nothing's changed. Is it even possible to assign r(max) to a variable in any way?
    And can someone think of another way to automatically assign that observation (and others) with values of cluster that aren't assigned yet? (all these observations currently hold the value 1 in cluster).

    Thanks a lot in advance,
    Ben

  • #2
    Is town_code a variable? You should make sure the replace command immediately follows the summarize command. It could also be precision. You can try

    Code:
    replace cluster= `r(max)' + 1  if town_code==float(1997)
    Last edited by Andrew Musau; 03 Apr 2019, 07:47.

    Comment


    • #3
      It must has been some precision issue or a command I put between the two lines, because it's now working.
      Thanks a lot,
      Ben

      Comment

      Working...
      X