Announcement

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

  • Variables not related to series

    Hi, there is a way to declare and use variables not related to a field o series, I mean, could I do create variables like this

    declare var as integer or something like that?

    because generate or egen make series.

  • #2
    I don't get it. Maybe post some data using dataex and state what you need more specifically.

    Comment


    • #3
      how do I create free variables? since generate or egen create series, how can I create free variables?

      Comment


      • #4
        Hi, there is a way to declare and use variables not related to a field o series
        I do not know what you mean by "a field o series", nor what you intend in post #3 by "free variables". Do you perhaps want to create variables that do not persist within your dataset after the execution of your do-file or program?

        Code:
        . sysuse auto, clear
        (1978 automobile data)
        
        . keep make price
        
        . ds
        make   price
        
        . tempvar gnxl
        
        . generate `gnxl' = 42
        
        . replace `gnxl' = `gnxl'+_n
        (74 real changes made)
        
        . list in 1/5
        
             +----------------------------------+
             | make            price   __000001 |
             |----------------------------------|
          1. | AMC Concord     4,099         43 |
          2. | AMC Pacer       4,749         44 |
          3. | AMC Spirit      3,799         45 |
          4. | Buick Century   4,816         46 |
          5. | Buick Electra   7,827         47 |
             +----------------------------------+
        
        . 
        end of do-file
        
        . ds
        make   price
        
        . list in 1/5
        
             +-----------------------+
             | make            price |
             |-----------------------|
          1. | AMC Concord     4,099 |
          2. | AMC Pacer       4,749 |
          3. | AMC Spirit      3,799 |
          4. | Buick Century   4,816 |
          5. | Buick Electra   7,827 |
             +-----------------------+
        
        .

        Comment


        • #5
          I think Daniel may have in mind that in many languages variables can be scalars, and indeed in Mata too an assignment such as

          Code:
          answer = 42 
          is perfectly fine. In Stata itself, you can hold text or numeric constants in macros or scalars. A good overview is given in

          https://www.stata.com/manuals/u18.pdf

          Occasionally it is a good idea to put a constant into a Stata variable:

          Code:
          gen answer = 42
          but usually that is a waste of memory.

          Comment


          • #6
            thank you Mr. Cox.

            Comment

            Working...
            X