# Create a multidimensional string array

Hello I am designing a procedure for some maximization that I want to do. The solution, are choices that agents do, and I want to store the numerical values (feasible) and the names of those choices (I don't know how to do it). Ideally, I was thinking to code something like the following:

struct res_wage {
array res_wage ;
string array names;
};

struct res_wage VF_no_work2;
VF_no_work2.res_wage = arrayinit(N_s|N_s|2|2|N_w|10,miss(1, 1)) ;

VF_no_work2.names =arrayinit(N_s|N_s|2|2|1|10,"hg") ;

But, the later shows an error, is there any way I can store the strings on different dimensions inside a structure definition?

Thank you

0

It might be simpler to make a multidimensional structure. I don't know the best way to lay out your data, but you can create vectors or arrays of structures.

``````new;

struct choices {
matrix wage;
string array name;
};

struct choices market_a;

// Initialize (if desired. you don't have to)
market_a.wage = { 1 2, 3 4 };
market_a.name = { "alpha" "beta", "gamma" "delta" };

// Reshape to a 9x2 matrix of 'choices' structures
market_a = reshape(market_a, 9, 2);

// Print the elements of the structure in row 3, column 2
print market_a[3,2].name;
print market_a[3,2].wage;``````

0

Thanks for your answer, I have a lot of dimensions that I am considering, can I do the areshape, instead of the reshape ( I tried and it didn't work)?

0

Structures can only be `reshaped` with two dimensions. However, you can make your structure the member of another structure if you need to get more dimensions.

`````` new;
struct choices {
matrix wage;
string array name;
};

struct choice_main {
struct choices c;
};

struct choice_main markets_all;

// Initialize (if desired. you don't have to)
markets_all.c.wage = { 1 2, 3 4 };
markets_all.c.name = { "alpha" "beta", "gamma" "delta" };

// Reshape substruct to a 9x2 matrix of 'choices' structures
markets_all.c = reshape(markets_all.c, 9, 2);

// Reshape main struct to a 4x3 matrix of 'choice_main' structures
markets_all = reshape(markets_all, 4, 3);

// Print the elements of the structure in row 3, column 2
print markets_all[2,1].c[3,2].name;
print markets_all[2,1].c[3,2].wage;``````

For this, I would create procedures to do the initialization of these structures to keep the complexity out of your main code. Good names will also help quite a bit.

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.