# Using JuMP.fix with a variable indexed by a string

**URL:** <https://discourse.julialang.org/t/using-jump-fix-with-a-variable-indexed-by-a-string/18386>\
**Category:** New to Julia\
**Created:** [December 6, 2018, 5:35pm UTC](https://discourse.julialang.org/t/using-jump-fix-with-a-variable-indexed-by-a-string/18386 "2018-12-06T17:35:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam\_christensen](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@adam\_christensen](https://discourse.julialang.org/u/adam_christensen)\
**Post date:** [December 6, 2018, 5:35pm UTC](https://discourse.julialang.org/t/using-jump-fix-with-a-variable-indexed-by-a-string/18386/1 "2018-12-06T17:35:20Z")

</div>

I am trying to fix a variable that I have previously defined as

```julia
factors = ["labor", "capital"]
@variable(mymodel, W[f in factors] => 0)

```

then using  
`JuMP.fix(W["labor"], 1)`

I’m new to Julia/JuMP so this could be simple, but it seems like if I can define a variable over a set of strings I should also be able to fix it, right? What am I missing? Thanks for the help!!

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [December 6, 2018, 7:49pm UTC](https://discourse.julialang.org/t/using-jump-fix-with-a-variable-indexed-by-a-string/18386/2 "2018-12-06T19:49:38Z")

</div>

Write a loop:

```julia
for f in factors
    JuMP.fix(W[f], 1.0)
emd
```

---

<div class="post-metadata">

**Author:** ![adam\_christensen](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@adam\_christensen](https://discourse.julialang.org/u/adam_christensen)\
**Post date:** [December 6, 2018, 8:09pm UTC](https://discourse.julialang.org/t/using-jump-fix-with-a-variable-indexed-by-a-string/18386/3 "2018-12-06T20:09:34Z")

</div>

I actually found out that my error stems from the `Complementarity.jl` package rather than my own `JuMP.fix` implementation. 😕 oh well…
