Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: use of local in variable name


From   Eric Sommer <sommer@fifo-koeln.de>
To   statalist@hsphsun2.harvard.edu
Subject   st: use of local in variable name
Date   Mon, 19 Sep 2011 12:57:01 +0200

...
Dear Stata-Users,

I want to program a job market simulation that matches employers and job-searchers according to their match. Employers receive up to ten job offers. If they have less than 10, I would like to save the firm's number in the respective variable offer_`x' (x from 1 to 10).
the code looks as follows:
---
forvalues s=1/$numberofjobs {
    if free[`s'] == 1{    // is the job free

// scalar c contains the index of the employer that matches best

     if (offers[c] < 10) {

        replace offers = offers + 1 if (_n == c)
        local x offers[c]
replace offer_`x' = `s' if (_n == c) // Applicant c gets job offer number x from firm s

}
---
However, offer_`x' is not assigned correctly. I get the following error code:

---
variable offers_offers not found
r(111);
---

But if I inspect the content of x with "di`x'", I get 1 as return (if ang[c] is 1)



On the contrary, if I type this, the variable is replaced correctly.
---
local x 1
replace offer_`x' = `s' if (_n == c)
---

Apparently, Stata interprets `x' differently when using "display" or "replace". What am I doing wrong? Or is there another way to replace offer_1 to offer_10 without this detour using locals?




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index