Announcement

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

  • Maximization problem -

    Hi,

    I would like to maximize the "item_price" (the variable of interest) of each "item". Each item appears in different "pack" with different quantity ("qty"). Here is the data that I have (small sample):

    Code:
    pack    item    qty    item_price    pack_price
    SNESYSA02E    1220-10    1        10
    SNESYSA02E    1220-11    1        10
    SNESYSA02E    220101091X    .0567        10
    SNESYSA02E    300204    1        10
    SNESYSA02E    302008    2        10
    SNESYSA02E    36004814    1        10
    SNESYSA02E    47394    2        10
    SNESYSA02E    48012    1        10
    SNESYSA02E    49279WH    1        10
    SNESYSA02E    50346A    4        10
    SNESYSA02E    8004000    1        10
    SNESYSA02E    8004002    1        10
    SNESYSA02E    8337A-BULK    1        10
    SNESYSA01I    49279WH    1        12
    SNESYSA01I    500.11.014    1        12
    SNESYSA01I    50346A    2        12
    SNESYSA01I    53784    1        12
    SNESYSA01I    8004000    1        12
    SNESYSA01I    8004002    1        12
    SNESYSA01I    8337A-BULK    1        12
    SNESYSA01I    8475-BULK    2        12
    SNESYSA01I    8520ZD-BULK    4        12
    SNESYSA01I    880901063    2        12
    SNESYSA01I    95157    1        12
    SNESYSA01I    BTCL35-BULK    1        12
    SNESYSA01I    BTCM15-BULK    1        12
    SNESYSA01I    BVGP150    3        12
    SNESYSA01I    BVKD700B    3        12
    SNESYSA01I    BVKD700Y    2        12
    SBASYSA08A    ALP/LSAS-61    1        9
    SBASYSA08A    ALP/MIS-3B/C    1        9
    SBASYSA08A    BTCL35-BULK    1        9
    SBASYSA08A    BVGP150    2        9
    SBASYSA08A    BVJ1400    1        9
    SBASYSA08A    BVKD700B    3        9
    SBASYSA08A    BVKD700Y    1        9
    SBASYSA08A    BVPB2025    1        9
    SBASYSA08A    BVQUIV    1        9
    SBASYSA08A    BVRG1010    5        9
    SBASYSA08A    BVRG3030    5        9
    SBASYSA08A    BVRP06L    2        9
    The ultimate goal is to populate the "item_price" variable such that "qty * item_price" = "pack_price".

    I have tried to use the command optimize init() but I could not make it run. Here is the help link:
    http://www.stata.com/manuals13/m-5optimize.pdf

    I have been struggling with this issue for a while. If you need any clarification/ additional information, I am more than happy to bring them. Help would be highly appreciated. Thanks!





  • #2
    This is the third thread you have started on this same question. You got no answers from the previous two. You did get advice to make your question clearer, and you were specifically advised to read the FAQ about how to do that and follow the instructions there.

    But here you are again, a third time, with no clearer question than before, and data still posted in an unwieldy, practically unusable, format. If you want answers, you have to help the people who would help you.

    Comment


    • #3
      Clyde,

      I have followed the FAQ that recommend to re-write the question. I do not know how to make it more clear. This is a very standard optimization problem that I just can't program in Stata.

      I really need help so I am kindly asking you. What is not clear? How can I help you understand? How can I provide more information so that you can help me program that in Stata?

      As for the data, I have done a copy/paste from the Stata data editor that has never caused problem. I am attaching at *.dta file if that can help. Thanks a lot in advance.

      Attached Files

      Comment


      • #4
        The previous thread actually said more about the problem: http://www.statalist.org/forums/foru...-optimize-init

        As before, sorry, I don't understand the problem and what I don't understand is almost all of it, so I am not asking you to explain anything extra. For every field, people inside understand a lot, people outside understand almost nothing.

        In turn the point has now been made several times that repeated posting of the same problem is usually futile, so don't be surprised if we give up too. No ill will, just other things to do.

        Comment


        • #5
          I think that what you are trying to accomplish is not well suited to the optimization techniques featured in the Mata commands you are attempting to use. To begin with, the optimize routines require definition of a scalar function that you are trying to maximize or minimize. What might that function be for your example? Your parameters are the individual item prices. You have for each pack a constraint that the sums of the products of prices and quantities must equal the pack price. (And it is possible that those constraints cannot all be satisfied.) But you have no objective function to maximize.

          In general, my background suggests that this is not a statistical problem, in that you have no random component. That doesn't automatically remove it from consideration by Stata (I've used Stata to balance my checkbook, which had better be non-random) but it does suggest there may be better suited tools and techniques. In particular, this sounds like the start of a linear optimization problem, based on what I remember from my studies in the early 1970's of what was then called operations research.

          Let me add that with regard to
          As for the data, I have done a copy/paste from the Stata data editor that has never caused problem.
          the example you pasted above shows five variable names and four columns of data. Using dataex as has been recommended to you in the FAQ would clarify this situation, and would make it trivial to read your sample data into Stata. The less convenient it is for others to explore your problem, the less likely you are to find others willing to advise you. Although in this case, as suggested above, Stata does not appear to be the appropriate tool for the task at hand.
          Last edited by William Lisowski; 18 Mar 2016, 08:49.

          Comment


          • #6
            William,

            First of all, I wanted to thank you for helping me with the problem, I sincerely appreciate it!

            I guess I am trying to solve a problem with a Stata tool that would be similar to the Excel Solver. I have defined clearly the objective fonction in the code + comments below. One can run the following code starting from the small sample of data enclosed:

            Code:
            * "item_price" is the variable to optimize
            * I allocate an initial value that is the average between the upper and lower price contraint 
            gen item_price = (item_min_price + item_max_price)/2
            
            * "item_price" time "qty" 
            gen item_price_qty = item_price*item_qty
            
            * Sum all the "item_price_qty" by "pack"
            * This variable will be used to define the objective function
            bys pack: egen sum_item_price_qty = total(item_price_qty)
            
            * "e" is the objective function to be be MINIMIZED
            * We want the sum of "e" across "pack" to be MINIMIZED
            gen e = abs(sum_item_price_qty - pack_price)
            
            * The minimzation problem is subject to the following vector of constraints:
            * item_min_price < item_price < item_max_price
            
            ***************************************************
            * The sum of the following rows has to be minimized (by changing the "item_price" variable")
            collapse (mean) e , by(pack)
            ***************************************************


            Attached Files

            Comment


            • #7
              Your example reinforces my belief that this problem is not well suited to Stata and the Mata optimize routines.

              In general, constrained optimization in a statistical context involves finding the maximum of a reasonably smooth multiparameter objective function, where constraints are linear combinations of the parameters that have the effect of reducing the dimensionality of the parameter space without affecting the form of the objective function.

              The constrained optimization represented by this problem is a different sort. The inclusion of the absolute value function means the objective function is not smooth. The constraints put boundaries on the parameter space, beyond which the objective function is effectively undefined.

              While it may be possible to use the tools of Stata to write a program that solves this problem, it seems unlikely that you will find a ready-made solution.
              Last edited by William Lisowski; 19 Mar 2016, 09:43.

              Comment


              • #8
                William,

                The objective function can be redefine as strictly positive instead of absolute value. How would you solve the problem then? Thanks!

                Comment


                • #9
                  Not using Stata, because your constraints are not the sort that are implemented in Stata.

                  Comment


                  • #10
                    What if I only keep the upper bound constraints (and not the lower bound). How would you code it then. Thanks

                    Comment


                    • #11
                      Half as many inequality constraints is still too many.

                      Comment


                      • #12
                        How would you implement it with the penalty method?

                        Comment


                        • #13
                          Above I wrote

                          While it may be possible to use the tools of Stata to write a program that solves this problem, it seems unlikely that you will find a ready-made solution.
                          I would look for a ready-made solution, not limiting myself to Stata.

                          Comment


                          • #14
                            William,

                            I am insisting because I was asked to perform the task in Stata. I wouldn't want to require to swich software unless it is absolutely impossible to do it with Stata.

                            I am bringing up the penalty method because someone mentioned in in the forum. I'm just unsure how to implement it based on the post:
                            http://www.statalist.org/forums/foru...-mata-optimize

                            Any idea?

                            Comment


                            • #15
                              Those recommendations, in my judgement, fall squarely into the realm of using the tools of Stata to write a program that solves this problem: they're a long way from getting optimize_init() to run. While familiar with penalty function methods, I have not written programs to implement them, in Stata or any other language, and have no advice to offer, other than not underestimating the difficulty involved in following to a solution either of the paths discussed in the cited thread.

                              Comment

                              Working...
                              X